Im try to create a spinner dynamically on press of a button.
this is what i did:
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
}
});
}
}
My issue is im not able to get that toast, ie the spinners onitemselectedlistner is not triggering.
Any suggestion will be greatly appreciated.. Thanks
Spinner need to add in a parent to get call on
onItemSelectedAdd the sppiner in XML and set width and height 0dp (may set visibility Invisible not gone).
Get that using
findViewById.