如何更改不再在屏幕上的可扩展列表视图子项的背景

发布于 2024-11-09 16:47:42 字数 274 浏览 5 评论 0原文

在 setOnChildClickListener 中,我可以使用 v.setBackgroundResource(R.color.blue); 更改子项的背景(我无法使用 xml 列表项选择器,因为我正在做一些分屏内容和焦点丢失)当选择另一个孩子时,我还可以将颜色设置回来。但是,当选定的子项滚动到屏幕外时,它不会返回到原始颜色,并且当父项折叠时,如果选择了该父项内的子项,它将跳到下一个父项并更改父项的背景那里的孩子,因为根据 android 的说法,折叠的行不再存在。关于如何修复这些错误有什么建议吗?

In a setOnChildClickListener, I am able to change the background of a child item with v.setBackgroundResource(R.color.blue); (I can't use an xml list item selector because I am doing some split screen stuff and focus gets lost) I am also able to set the color back when another child is selected. However, when a selected child is scrolled off screen, it does not go back to the original color and when a parent is collapsed, if a child inside that parent was selected, it will hop down to the next parent and change the background of a child in there since the collapsed rows no longer exist according to android. Any tips on how to fix these bugs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

青瓷清茶倾城歌 2024-11-16 16:47:42

您需要存储选择的项目,然后创建一个自定义适配器,该适配器在其 getView() 方法中返回具有适当背景的视图

You need to store which item was selected, then make a custom adapter which in its getView() method returns a view with the appropriate background

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