Android Spinner Error:Android.View.Windowmanager$Badtokenexception: Unable to Add Window

Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window

I think you have context problem.Try to get context using below method

you can create a new activity and set its theme to dialog theme so that when you start your activity it will display as dialog.
For more information about dialog see below post

Click here

EDIT2

I found a solution for badTokenExcaption

In your activity's onCreate() method replace the line setContentView(R.layout.XXXXX) by

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.XXXXX, null);
this.setContentView(viewToLoad);

and replace the spinner code by following lines

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.medicine_types, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spDosageType.setAdapter(adapter);

android.view.WindowManager$BadTokenException while clicking on android spinner

I found a solution for badTokenExcaption

In your activity's onCreate() method replace the line setContentView(R.layout.XXXXX) by

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.XXXXX, null);
this.setContentView(viewToLoad);

and replace the spinner code by following lines

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.medicine_types, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spDosageType.setAdapter(adapter);

Bad token exception on spinner which uses (android:entries=@array/type) in fragment

I solved that error by putting my popup's XML code in fragment and make it visible on click. By that way spinner's code runs nicely on every device that way error must be somewhere in using spinner in custom popup.

Click on spinner gives WindowManager$BadTokenException

pass

YourActivty.this.getParent()

as Context to the Spinner.

For more information see here and here



Related Topics



Leave a reply



Submit