列表中带有 Checkable 接口的 LinearLayout setChecked 在项目单击时未调用

发布于 2024-12-26 08:01:57 字数 374 浏览 5 评论 0原文

我正在尝试列出项目清单。这些项目包含一个复选框和一个自定义视图。我希望这些复选框具有自定义图像,因此我更改了复选框主题。 我的第一个想法是创建一个带有复选框和自定义视图的可检查线性布局。 出现的问题是复选框获得了该项目的焦点,但因为我希望整个项目在单击时具有不同的背景,所以我不希望复选框获得焦点。这就是为什么我改变了我最初的想法来实现一个可绘制的对象,该可绘制的对象将代表该项目的选中状态(可绘制的对象将在单击该项目时被替换)。现在出现的问题是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的味道 2025-01-02 08:01:57

在 ListView 上调用 setSelection(position) 解决了我的问题。现在调用可检查布局上的方法。

亲切的问候,
布拉姆

Calling setSelection(position) on my ListView solved my problem. Methods on the checkable layout get called now.

Kind regards,
Bram

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文