Android旋转器:获取选定的项更改事件当所选项发生更改时,如何为旋转器设置事件侦听器?基本上,我想做的是类似这样的事情:spinner1.onSelectionChange = handleSelectionChange;void handleSelectionChange(Object sender){
//handle event}
3 回答
隔江千里
TA贡献1906条经验 获得超10个赞
旋转器不支持项目单击事件。调用此方法将引发异常。
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { // your code here } @Override public void onNothingSelected(AdapterView<?> parentView) { // your code here }});
onCreate()
LEATH
TA贡献1936条经验 获得超6个赞
Spinner spnLocale = (Spinner)findViewById(R.id.spnLocale);spnLocale.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // Your code here } public void onNothingSelected(AdapterView<?> adapterView) { return; } });
注:
OnItemSelectedListener
旋转初始化 用户手动选择
吃鸡游戏
TA贡献1829条经验 获得超7个赞
AdapterView.OnItemSelectedListener
onCreate()
Spinner spin = (Spinner) findViewById(R.id.spinner);spin.setOnItemSelectedListener(this);
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { selection.setText(items[position]);}public void onNothingSelected(AdapterView<?> parent) { selection.setText("");}
- 3 回答
- 0 关注
- 315 浏览
添加回答
举报
0/150
提交
取消