exception - Selecting Android Spinner Causes WindowManager$BadTokenException -
i created custom alertdialog display spinner , edittext elements. when select menu option, custom alertdialog gets launched. works fine until select spinner try , select item, @ point badtokenexception. i've read other stackoverflow posts saying similiar exceptions result of trying display diaglog using getapplicationcontext() rather passing activity.this. i'm not explicitly passing getapplicationcontext() related alertdialog.
to setup custom alertdiaglog, created layout file containing spinner , edittext elements, , made alertdialog use layout:
layoutinflater inflater = (layoutinflater)getapplication().getsystemservice(layout_inflater_service); view layout = inflater.inflate(r.layout.custom_layout, (viewgroup)findviewbyid(r.id.custom_layout_root)); spinner = (spinner)layout.findviewbyid(r.id.custom_layout_spinner); arrayadapter adap = arrayadapter.createfromresource(activity.this, r.array.data, android.r.layout.simple_spinner_item); adap.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner.setadapter(adap); spinner.setonitemselectedlistener(new spinneritemlistener()); alertdialog.builder dialog = new alertdialog.builder(activity.this); dialog.settitle("title"); dialog.setpositivebutton("ok", new dialog.onclicklistener() ... ... dialog.show();
this code works fine displaying alertdialog. however, when touch spinner, following problem:
thread [<3> main] (suspended (exception windowmanager$badtokenexception)) viewroot.handlemessage(message) line: 1704 viewroot(handler).dispatchmessage(message) line: 99 looper.loop() line: 123 activitythread.main(string[]) line: 4203 method.invokenative(object, object[], class, class[], class, int, boolean) line: not available [native method] method.invoke(object, object...) line: 521 zygoteinit$methodandargscaller.run() line: 791 zygoteinit.main(string[]) line: 549 nativestart.main(string[]) line: not available [native method]
does have idea of what's going on? exception message says:
unable add window -- token null not application
i believe message others have seen type of problem, i'm assuming applicationcontext somewhere in mix, i'm not sure where. manifest setup minsdk of 1.5 target sdk of 1.6.
i've read other stackoverflow posts saying similiar exceptions result of trying display diaglog using getapplicationcontext() rather passing activity.this.
i'm not explicitly passing getapplicationcontext() related alertdialog.
presumably line of code is doing — you're asking application
use context access service, rather of current window
:
layoutinflater inflater = (layoutinflater) getapplication().getsystemservice(layout_inflater_service);
can't replace version below, since you're launching alertdialog
activity
?
layoutinflater inflater = (layoutinflater) getsystemservice(layout_inflater_service);
or simpler:
layoutinflater inflater = getlayoutinflater();
Comments
Post a Comment