【鼠】安卓学习杂记(十)——Android开源下拉框Nice Spinner的使用
程序员文章站
2022-05-13 15:09:09
...
一、效果图
二、GitHub网址
https://github.com/arcadefire/nice-spinner
三、使用方法
1、添加依赖
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation 'com.github.arcadefire:nice-spinner:1.3.4'
}
2、XML中实现
<org.angmarch.views.NiceSpinner
android:id="@+id/nice_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
3、Java中实现
NiceSpinner niceSpinner = (NiceSpinner) findViewById(R.id.nice_spinner);
List<String> dataset = new LinkedList<>(Arrays.asList("菜单一", "菜单二", "菜单三", "菜单四", "菜单五"));
niceSpinner.attachDataSource(dataset);
4、设置菜单被选中的监听事件
niceSpinner.addOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
Toast.makeText(MainActivity.this, "已选定菜单一", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(MainActivity.this, "已选定菜单二", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(MainActivity.this, "已选定菜单三", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(MainActivity.this, "已选定菜单四", Toast.LENGTH_SHORT).show();
break;
case 4:
Toast.makeText(MainActivity.this, "已选定菜单五", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(MainActivity.this, "无选定任何菜单", Toast.LENGTH_SHORT).show();
}
}
});
四、其他属性(详见GitHub)
上一篇: make工程管理器之makefile详解
下一篇: 第六载:makefile变量的高级主题