2

I am showing PopupWindow on button click like this.

public void Search_Click(View view) {
    try 
    {
      Display display=getWindowManager().getDefaultDisplay();
      LayoutInflater inflater = (LayoutInflater) IssueTokenActivity.this
                                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View layout = inflater.inflate(R.layout.activity_pop_up_transporter_details,
                        (ViewGroup) findViewById(R.id.popup_element));
      AutoCompleteTextView act=(AutoCompleteTextView)layout.findViewById(R.id.act_trans_name);
        ArrayAdapter<String> dataadapter=new ArrayAdapter<String>(view.getContext(), android.R.layout.simple_dropdown_item_1line,list);
        dataadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        act.setAdapter(dataadapter);
        act.setThreshold(1);

        //TODO: Need to support for higher API
        pwindo = new PopupWindow(layout,display.getWidth()-60, display.getHeight()-400, true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

        btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
        btnClosePopup.setOnClickListener(cancel_button_click_listener);

    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}

But I am getting this error while typing in AutoCompleted TextView.

06-20 09:15:47.091: E/AndroidRuntime(23277): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@40ece840 is not valid; is your activity running?
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.widget.PopupWindow.invokePopup(PopupWindow.java:993)
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:899)
06-20 09:15:47.091: E/AndroidRuntime(23277):    at android.widget.ListPopupWindow.show(ListPopupWindow.java:603)
Giri
  • 931
  • 11
  • 31
  • 51
  • Don't inflate the layout file and add it to the `R.id.popup_element` ViewGroup and then add that inflated layout as the content for the `PopupWindow`. – user Jun 20 '13 at 09:37
  • Thanks,Can you give some more detail? – Giri Jun 20 '13 at 10:13
  • For start use `View layout = inflater.inflate(R.layout.activity_pop_up_transporter_details, null);` and see if the error goes away. – user Jun 20 '13 at 10:43
  • No still getting the same error – Giri Jun 20 '13 at 10:55
  • 2
    It seems that you can't show another `PopupWindow` from a `PopupWindow` and that is exactly what the `AutoCompleTextView` does. See http://stackoverflow.com/questions/11932578/can-android-popupwindow-show-another-popupwindow – user Jun 20 '13 at 11:37
  • Did you find a way to fix the error I am facing the same problem? – fadz Jun 27 '14 at 14:00
  • No as far as i know there is noway to do this..As @Luksprog said we can't have popupwindow in another popupwindow. – Giri Jul 02 '14 at 05:13
  • Refer here [Autocomplete TextView in PopupWindow](https://stackoverflow.com/questions/21303527/autocompletetextview-not-working-inside-popup-window/56680894#56680894) – Kunchok Tashi Jun 20 '19 at 07:23
  • I seemed to have same problem. Please refer here [autocompletetextview not working inside popup window](https://stackoverflow.com/questions/21303527/autocompletetextview-not-working-inside-popup-window/56680894#56680894) – Kunchok Tashi Jun 20 '19 at 07:24

1 Answers1

1

Better to use dialog(android.app.Dialog) to implement AutoCompleteTextView.In my opinion its not possible to add AutoCompleteTextView in PopupWindow(you will get Exception).You can add Spinner in Popupwindow.You can implement both if are using dialog instead of popup.

Jinosh P
  • 341
  • 2
  • 8