0

我有一个微调器列表"one","two","three"

我想为(that means when click spinner)微调器中的每个选择调用一个方法。

单击微调器时是否有任何默认方法可用。那么怎么做

4

2 回答 2

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
}

});
于 2012-07-31T09:39:41.800 回答
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
}

});
于 2012-07-31T09:59:36.593 回答