I've been searching the web for the solution to this problem, but, unfortunately, I can't seem to find the answer. I created an XML file for a PopupWindow with a Spinner inside of it. Inside a button event listener, I call the following code to inflate the PopupWindow and display it on the screen.
LayoutInflater inflater = getLayoutInflater();
settings_layout = inflater.inflate(R.layout.setting_popout, (ViewGroup) findViewById(R.id.setting_popout));
// Creates a popup window of required width and height, and displays
// the popup in the center of the screen.
pw_settings = new PopupWindow(settings_layout, 400, 470, true);
pw_settings.showAtLocation(settings_layout, Gravity.CENTER, 0, 0);
spColors = (Spinner) settings_layout.findViewById(R.id.linecolor);
// Sets the initial values of the color spinner and the listener
ArrayAdapter<CharSequence> adapter_color =
ArrayAdapter.createFromResource(this, R.array.colors_array, android.R.layout.simple_spinner_item);
adapter_color.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spColors.setAdapter(adapter_color);
spColors.setSelection(adapter_color.getPosition(over.color));
When clicking the button, the popup window shows up fine. However, I get the following error in LogCat when I click on the Spinner.
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41402a90 is not valid; is your activity running? ...
I'm not sure what I'm doing wrong. Any help would be greatly appreciated! Thank you!