可点击某个子视图列表视图项的单击事件无法通过该项目的子视图视图、目的、该项、单击

2023-09-05 00:49:06 作者:?優雅:轉身.

我有一个列表视图中,每个项目都有一个可点击的TextView,当我点击了TextView的,然后把它变成两个按钮,如果我点击我需要整个项目能够响应点击事件的TextView的外面。

我仍然有一个工作线程获取从互联网上的东西,然后更新列表视图。 当一个工作线程通知列表视图的适配器notifydatasetchange,并在同一时间,我单击列表中的项目TextView的,但奇怪的事情发生了,我点击的TextView但整个项目响应点击。

我知道这是由ListView的循环机制。 在正常sitituation,notifydatasetchanged时,列表视图会放弃之前发布的事件。但有些时候也不能放弃。但我想知道的是有一些workround避免这种情况?我希望ListView的项目可以放弃这一贴notifydatasetchange之前的事件。

解决方案

 < RelativeLayout的
    ...
    机器人:descendantFocusability =blocksDescendants
>

    <按钮
        ...
        机器人:可聚焦=假
    />

< / RelativeLayout的>
 

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.

超级赞 利用Photoshop设计打造大气的木板条纹立体字

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.

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>