Android中ListView放入PopupWindow产生问题解决

今天在做项目时候发现将ListView放入PopupWindow产生问题,ListView放入PopupWindow后
对PopupWindow设置了setFocusable(true)这时候其他的控件全部没有响应了!
我的解决方案是,ListView放入PopupWindow后对你对PopupWindow设置了setFocusable(true);
让PopupWindow获得了焦点这时候你点击其它控件是无法响应的。
这时候你可以通过pw(PopupWindow对象).getContextView()拿到他的父视图。

然后通过给父视图注册事件 让pw失去焦点 我是这样做的:

    pw.getContentView().setOnTouchListener(new OnTouchListener(){  
      
                                            @Override  
                                            public boolean onTouch(View v, MotionEvent event) {  
                                                    // TODO Auto-generated method stub  
                                                    pw.setFocusable(false);//失去焦点  
                                                    pw.dismiss();//消除pw  
                                                    return true;  
                                            }  
                                              
                                    });  

  

原文地址:https://www.cnblogs.com/jsonfan/p/5329291.html