PopupWindow $BadTokenException: Unable to add window — token null is not valid

后端 未结 11 2196

I have the following error when showing a PopupWindow. The errors are triggered by the line:

checkInPopup.showAtLocation((ViewGroup) mapView.getParent(), Gra         


        
11条回答
  •  野性不改
    2020-11-27 05:22

    Try to show the pop like below

    findViewById(R.id.main_layout).post(new Runnable() {
            public void run() {
                mPopupWindow.showAtLocation(findViewById(R.id.main_layout), Gravity.CENTER, 0, 0);
                Button close = (Button) customView.findViewById(R.id.btn_ok);
                close.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        doOtherStuff();
                    }
                });
            }
        });
    

提交回复
热议问题