I know that there are so many similar questions, but I answered my problem (or I did not find the answer I need. ..)
In my menu on the actionbars (On Option Option Selected) I open the popup for user settings. Checkboxes and radiobuttons good job, but if spinner I tab, there will be a serious exception:
Fatal Exception: Main android.view.WindowManager $ BadTokenException: Unable to add window - token Android .view.ViewRootImpl $ W @ 42766f00 is not valid; Is your activity going on? The code in onOptionsItemSelected Method: LayoutInflater inflaterSettings = LayoutInflater.from (reference); Settings with final linear length = (linear layout) inflaterSettings.inflate (R.layout.actionbar_menu_settings_popup, tap); Spinner spinner = (spinner) lathets. FindVibIID (RID spinner_action_settings_intolar_value); ArrayAdapter & LT; CharSequence & gt; Adapter = Arrayadapter. Cethefrom Resource (this, R. Night: Action_setting_interval_value, AndroidR.Light.Simple_spinner_item); Adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); Spinner.setAdapter (adapter); spinner.setOnItemSelectedListener (New OnItemSelectedListener () {@Override public void onItemSelected (AdapterView & LT ;? & gt; parent, views, Int position, long id) {TODO} @Override public void onNothingSelected (AdapterView & LT ;? & Gt; parent) {// to}}}; Popup window popup = new popup window (context); PopUp.setContentView (llSettings); llSettings.post (new Runnable () {@Override public void run () {popUp.showAtLocation (llSettings, Gravity.CENTER, 0, 0) ;. int width = getResources () getDisplayMetrics () widthPixels ;. int height = getResources ( ) .getDisplayMetrics (). Height pixels, width = (int) (width * 0.9); height = (int) (height * 0.9); popup.update (width, height);}}); My actionbar_menu_settings_popup.xml:
& lt; Spinner Android: id = "@ + id / spinner_action_settings_intervall_values" Android: layout_width = "wrap_content" Android: layout_height = "Wrap_content" Android: drawSelectorOnTop = "true" Android: Entries = "@ARA / Action_Stats_intolar_value" /> and in string.xml:
& lt; String-array name = "action_settings_intervall_values" & gt; & Lt; Items & gt; 5 & lt; / Item & gt; & Lt; Items & gt; 15 & lt; / Item & gt; & Lt; Items & gt; 30 & lt; / Item & gt; & Lt; Items & gt; 45 & lt; / Item & gt; & Lt; Items & gt; 60 & lt; / Item & gt; & Lt; Items & gt; 120 & lt; / Item & gt; & Lt; Items & gt; 180 & lt; / Item & gt; & Lt; / String array & gt; Edit has logged in a onOptionsItemSelected : Log .i ("main activity # onCreateOptionsItems", "context:" + reference); Logs. I ("Main Activity # Create Option", "getApplicationContext:" + getApplicationContext ()); Logs. I ("main activity # onCreateOptionsItems", "this:" + this); Result:
06-21 10: 40: 58.185: I / Main activation # onCreateOptionsItems (14463): Reference: de.xy.app. activities the main activity @ 42743818 06-21 10: 40: 58.185: I / main activity # Create option etc. (14,463) gain Krenapepshn Contact: Android.ap.applogn @ 42741d48 06-21 10: 40: 58.185: I / main activity # Prkriyaopeshnsims (14463): it: De.xy.app.activities.MainActivity@42743818
Change the line
Arrayadapter & lt; Charsensen & gt; Adapter = Arrayadapter. Cethefrom Resource (this, R. Night: Action_setting_interval_value, AndroidR.Light.Simple_spinner_item); To do
Arrayadapter & lt; Charansensen & gt; Adapter = ArrayAdapter.createFromResource (getApplicationContext (), R.array.action_settings_intervall_values, android.R.layout.simple_spinary_item); This is usually caused by a bad reference reference
No comments:
Post a Comment