具有可点击子视图的listview项有时无法将click事件传递到该项目的子视图 [英] listview item with clickable subview sometime can't pass the click event to the item's subview

查看:68
本文介绍了具有可点击子视图的listview项有时无法将click事件传递到该项目的子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,每个项目都有一个可单击的文本视图,当我单击该文本视图时,将其更改为两个按钮,如果我单击该文本视图的外部,则需要整个项目都可以响应单击事件.

I have a list view , each item has a clickable textview, when I click the textview, then change it into two buttons, if I click the outside of the textview I need the whole item can respond to click event.

我仍然有一个工作线程可以从互联网上获取信息,然后更新列表视图.当工作线程通知列表视图的适配器notifydatasetchange时,同时,我单击列表项中的textview,但是发生了奇怪的事情,我单击了textview,但是整个项目都对单击做出了响应.

I still have a worker thread to get something from internet, then update the listview. When a worker thread notify the list view's adapter notifydatasetchange, and at the same time, I click the textview in a item of the list, but strange things happen, I click the textview but the whole item respond to the click.

我知道这是由listview的回收机制引起的.在正常情况下,当notifydataset更改时,listview将放弃之前发布的事件.但是有时候它不会放弃.但是我想知道是否有一些避免这种情况的解决方法?我希望listview的项目可以放弃在notifydatasetchange之前发布的事件.

I know this is caused by listview' recycle mechanism. At the normal sitituation, when notifydatasetchanged, the listview will give up the event posted before. But some times it doesn't give up. But I want to know is there some workround to avoid this? I hope the listview's item can abandon the event that posted before notifydatasetchange.

推荐答案

<RelativeLayout
    …
    android:descendantFocusability="blocksDescendants"
>

    <Button
        …
        android:focusable="false"
    />

</RelativeLayout>

这篇关于具有可点击子视图的listview项有时无法将click事件传递到该项目的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆