android - Button设置了focusable="false",还怎么监听到事件?
黄舟
黄舟 2017-04-18 09:15:19
0
2
561

由于使用了onItemClickListener,存在Button的时候ListView不能监听到点击事件,所以对Button做了如下处理

    android:focusable="false"
    android:focusableInTouchMode="true"

对Button的父类容器做这样的处理

    android:descendantFocusability="blocksDescendants"

之前的ListView监听问题解决了
但是,不知道后续应该怎么做了,我想在button上也添加事件,但是我理解的状态是:目前不能添加事件了,我理解的对不对,请各位大神指教

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
小葫芦

Do not use the onItemClick event provided by ListView.
Register the onClick event when initializing ItemView.
Then register the onClick event for Button.

刘奇

Your understanding is wrong.

ListViewItemViewIf any focusable View is used, the click event of ItemView will be intercepted by that type of View. To solve this problem, you only need to set the following attributes to RootView in layout-xml to solve the above problem:

android:descendantFocusability="blocksDescendants"

It would be nice if you still want to give ItemViewChildView设置OnClickListener, 那就直接调用View.setOnClickListener(OnClickListener).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template