I have a button in my xml. I want to pop up spinner programmatically not from xml after
clicking on button. but when i am clicking on the sbutton it is giving me an error.
Log output-:
android.view.WindoManager
$BadTokenException: Unable to add window--token null is not for an application
Here is my code:
b1.setOnclickListener(new View.OnClickListener(){
public void onClick(View v) {
List<String> list = new ArrayLIst<String>(Arrays.asList("a","s","d"));
Spinner t = new Spinner(getApplicationContext());
ArrayAdapter<String> adp = new ArrayAdapter<String>
(getApplicationContext(),android.R.layout.simple_spinner_item,list);
adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
t.setAdapter(adp);
t.performClick();
Give a try : Change the
getApplicationContext()withActivityName.thisI am sure this will give the correct token to show up the spinner.