我有一个包含"one","two","three"
,
我想在spinner中为每个选择(that means when click spinner)
调用一个方法。
单击微调器时是否有任何默认方法。如何操作
答案 0 :(得分:2)
您可以根据需要使用setOnItemSelectedListener
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
}
});
答案 1 :(得分:1)
这应该可以解决问题
Spinner sp = new Spinner(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new
String[]{"one", "two", "three"});
sp.setAdapter(aa);
sp.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
}
});