popupwindow

来源:互联网 发布:工商 安排网络监管人员 编辑:程序博客网 时间:2024/06/06 20:11
     今天突然想弄个demo的集合程序,想到了,用listView添加popupwindow,popupwindow中再次添加listView,结果发现,popupwindow中的listView无法响应点击item事件,无论怎么设置都不行,不知道这个点击事件被谁截取还是怎么的,后来发现有一个方法可以获取事件:在View类中有个
<span style="font-size:18px;">boolean android.view.View.dispatchKeyEvent(KeyEvent event)Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.</span>

会从视图树的顶部运行到当前焦点视图,

至此明白了,我设置了popupWindow的焦点,而popupWindow的焦点会给里面的view,也就是说popupWindow的焦点是在popupWindow内的listView中的,点击popupWindow是没有响应的,而当设置listView.setOnKeyListener(new OnKeyListener()点击事件后,就会给View中mOnKeyListener=1;从而使dispatchKeyEvent()的返回为true,那么View就会调遣关键事件到下一个视图,层层下来就会触发popupWindow内部的listView的click事件了。

0 0
原创粉丝点击