请参见此处:http: //developer.android.com/resources/tutorials/views/hello-spinner.html
你必须实现一个OnItemSelectedListener.
这里是链接的例子:
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext()), "The planet is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Run Code Online (Sandbox Code Playgroud)
如果您不想为侦听器显式声明类,也可以使用匿名内部方法.
| 归档时间: |
|
| 查看次数: |
3743 次 |
| 最近记录: |