PopupWindow中点击Spinner 显示Unable to add window android.view.ViewRoot is not valid is your activity running
天蓬老师
天蓬老师 2017-04-17 11:36:59
[Android讨论组]

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?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号