首页 > PopupWindow中点击Spinner 显示Unable to add window android.view.ViewRoot is not valid is your activity running

PopupWindow中点击Spinner 显示Unable to add window android.view.ViewRoot is not valid is your activity running

PopupWindow中点击Spinner 显示Unable to add window android.view.ViewRoot is not valid is your activity running

在MainActivity中有一个按钮事件,点击会弹出PopupWindow

send_data.setOnClickListener(new Popup_Window());

class Popup_Window implements View.OnClickListener{
   public void onClick(View v){
        popupwindow_view = getLayoutInflater().inflate(R.layout.pop, null,false);

//R.layout.pop 是一个自定义的xml

        popup_window=new PopupWindow(popupwindow_view,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,true);

            popupwindow_view.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {
                    if(popup_window!=null && popup_window.isShowing()){
                        popup_window.dismiss();
                        popup_window=null;
                    }
                    return false;
                }
            });

            Spinner spinner = (Spinner) popupwindow_view.findViewById(R.id.language);
            ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(getApplicationContext(),
                    R.array.language, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);


            ColorDrawable dw = new ColorDrawable(Color.parseColor("#99000000"));
            popup_window.setBackgroundDrawable(dw);
            popup_window.showAtLocation(v, Gravity.CENTER, 0, 0);
        }
    }

界面出现后一点击,这个Spinner 下拉菜单,应用就会崩溃,,,,
catlog: Unable to add window is your activity running?

【热门文章】
【热门文章】