保留按下的 ListView 项目的子视图的未按下状态
我有一个 ListView,其中包含每个项目中带有 ImageView 的项目。此 ImageView 有一个 OnClickListener。我设置了一个 XML 背景来设置按下状态和正常状态的可绘制对象。 ListView 上的 onItemClick 和 ImageView 上的 onClick 按预期触发,但问题是当我单击该项目(而不是 ImageView 上)时,它还会显示 ImageView 上的按下状态。在这种情况下,我想保持 ImageView 的正常状态...
我尝试了duplicateParentState =“false”,玩焦点等。我还没有找到解决方案。
有谁知道如何解决这个问题?
谢谢你, 埃尔万
I have a ListView which contains items with an ImageView in each item. This ImageView has a OnClickListener. I set a XML background to set drawables for pressed and normal states.
The onItemClick on the ListView and onClick on the ImageView are fired as expected, but the thing is when I click on the item (not on the ImageView), it also show the pressed state on the ImageView. I want to keep the normal state on the ImageView in this case...
I tried duplicateParentState="false", played with the focus, etc. I didn't find the solution yet.
Does anyone have an idea how to fix that?
Thank you,
Erwan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过向列表视图项目的内部项目添加可点击属性解决了这个问题。之后,列表视图项不再与可单击的视图共享按下状态。
只需添加:(
在 4.1 上测试)
希望这可以对某人有所帮助,我个人找不到如此简单的解决方案。
I solved this problem by adding clickable attribut to inner items of my listview item. After that listview item not share pressed state with views, which are clickable.
Just add:
(tested on 4.1)
Hope this could help to someone, I personally could not find so simple solution.
我在使用 ListView 进行的一些实验中发现,列表项中只有一个元素可以支持 onClickListener - 但我还没有找到任何支持这一想法的文档。
例如,如果您列出的项目包含复选框或评级栏,那么我将无法为其包含的列表项目触发 onClick 事件
I've found in some of my experiments with ListView that only one element in the listitem can support an onClickListener - I haven't found any documentation that supports this idea though.
e.g if you list item contained a checkbox, or a ratingbar then I wouldn't be able to fire an onClick event for the listitem it is contained within