列表中带有 Checkable 接口的 LinearLayout setChecked 在项目单击时未调用
我正在尝试列出项目清单。这些项目包含一个复选框和一个自定义视图。我希望这些复选框具有自定义图像,因此我更改了复选框主题。 我的第一个想法是创建一个带有复选框和自定义视图的可检查线性布局。 出现的问题是复选框获得了该项目的焦点,但因为我希望整个项目在单击时具有不同的背景,所以我不希望复选框获得焦点。这就是为什么我改变了我最初的想法来实现一个可绘制的对象,该可绘制的对象将代表该项目的选中状态(可绘制的对象将在单击该项目时被替换)。现在出现的问题是 setChecked 没有被调用。调用的不是 setChecked,而是 onClick(如果我向布局添加侦听器)。 Checkable 接口不应该在点击时提供对 setChecked 的调用吗?有人可以详细说明一下吗?
预先感谢
亲切的问候, 布拉姆
I am trying to make a list with items. These items contain a checkbox and a custom view. I want these checkboxes to have a custom image so I changed the checkbox theme.
My first idea was to create a checkable linearlayout with a checkbox and a custom view.
The problem occurred that the CheckBoxes took focus of the item but because I want the whole item to have a different background on click I do not want the checkboxes to take focus. That's why I changed my original idea to implementing a drawable that will represent the checked state of the item (the drawable will be replaced on click of the item). Now the problem occurs that the setChecked is not getting called. Instead of setChecked, the onClick (if I add a listener to the layout) is getting called. Shouldn't the Checkable interface provide a call to setChecked on click? Could someone elaborate?
Thanks in advance
Kind regards,
Bram
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ListView 上调用 setSelection(position) 解决了我的问题。现在调用可检查布局上的方法。
亲切的问候,
布拉姆
Calling setSelection(position) on my ListView solved my problem. Methods on the checkable layout get called now.
Kind regards,
Bram