How to create a Spinner widget inside of a PopupWindow in Android? Get BadTokenException when clicking on Spinner

南楼画角 提交于 2019-12-06 16:06:00

It may be a bit late, and not exactly an answer to the original question, but I found from another question here that inserting the following line into the xml for my spinner prevented that error from occurring.

android:spinnerMode="dialog"

I have run in to this problem a couple of times now, and the only non time consuming method I have found is the one proposed by Mike Fosker above.

android:spinnerMode="dialog"

makes the options list for the spinner show up in a separate pop-up, which does not trip the initial pop-up window you opened in your code. For example :

<Spinner
android:id="@+id/myspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />

Try:

settings_layout = inflater.inflate(R.layout.setting_popout, null);
((ViewGroup) findViewById(R.id.setting_popout)).addView(settings_layout);

Also, why are you attaching the layout in your popup to a ViewGroup already inside your activity? Chances are you can just get away with:

settings_layout = inflater.inflate(R.layout.setting_popout, null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!