我想在按钮的点击上以程序的形式创建一个 spinner:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.leave_balance);
spinner = new Spinner(this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, list);
spinner.setAdapter(spinnerArrayAdapter);
Button b = (Button)findviewbyid(R.id.button1);
b.setonclicklistener(new Onclicklistener){
public void onClick(View v) {
spinner.performClick();
}
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.maketext(context,"selectedspinner",Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
我的问题是不能获取 toast,比如 spinners 的 onitemselectedlistner 不能触发。
如何解决这个问题?