私はこの問題の解決策をウェブで探していましたが、残念ながら答えが見つからないようです。スピナーを内部に持つPopupWindowのXMLファイルを作成しました。ボタンイベントリスナー内で、次のコードを呼び出してPopupWindowを膨らませ、画面に表示します。
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));
ボタンをクリックすると、ポップアップウィンドウが正常に表示されます。ただし、スピナーをクリックすると、LogCatで次のエラーが発生します。
android.view.WindowManager $ BadTokenException:ウィンドウを追加できません-トークンandroid.view.ViewRootImpl $ W@41402a90は無効です。あなたの活動は実行されていますか?..。
何が間違っているのかわかりません。どんな助けでも大歓迎です!ありがとうございました!