0

what I am trying to do, is implement a dropdown inside a pop up menu. but when I click on the dropdown, I get this error

android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@c1d0e4f is not valid; is your activity running?

The pop up is call after the click of a button. This is how:

 btnCustomer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);

                View customView = inflater.inflate(R.layout.popup_customer,null);

                mPopupWindow = new PopupWindow(
                        customView,
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        true
                );

                if(Build.VERSION.SDK_INT>=21){
                    mPopupWindow.setElevation(5.0f);
                }

                ImageButton closeButton = (ImageButton) customView.findViewById(R.id.ib_close);
                spnDocumentType1 = customView.findViewById(R.id.spnCustomerDocumentType1);

                DocumentType documentType = new DocumentType();
                documentsTypeList = documentType.getDocumentTypes();
                String[] documentTypesDescription = new String[documentsTypeList.size()];
                for (int i = 0 ; i < documentsTypeList.size() ; i++) {
                    documentTypesDescription[i] = documentsTypeList.get(i).nameDocumentType;
                }
                ArrayAdapter<CharSequence> documentsTypeAdapter = new ArrayAdapter<CharSequence>(context,
                        R.layout.support_simple_spinner_dropdown_item, documentTypesDescription);

                spnDocumentType1.setAdapter(documentsTypeAdapter);

                //buildDocumentTypesAdapter(context);

                closeButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mPopupWindow.dismiss();
                    }
                });

                mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
            }
        });

Any help would be great thanks!

jvargas
  • 713
  • 1
  • 5
  • 13

1 Answers1

0

Adding android:spinnerMode="dialog" in spinner solved my problem. Solution taken from Error spinner in popup window when I click

jvargas
  • 713
  • 1
  • 5
  • 13