Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

Button设置了focusable="false",还怎么监听到事件?

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

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

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

    android:descendantFocusability="blocksDescendants"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你的理解不对.

ListViewItemView如果使用了任何focusable的View, 那么ItemView的点击事件就会被该类View给拦截了. 解决这个问题只需要给layout-xml中的RootView设置如下属性即可解决上述问题:

android:descendantFocusability="blocksDescendants"

如果还想给ItemViewChildView设置OnClickListener, 那就直接调用View.setOnClickListener(OnClickListener)就好了.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...