单击时将不同的可绘制对象设置为组和子列表

发布于 2024-11-18 13:49:59 字数 133 浏览 7 评论 0原文

我正在搜索有关 android 中的可扩展列表视图。 所以,我们知道有组列表和子列表...... 我想问是否可以,如果我想要不同的绘图 在组和子列表之间,当单击它们时...

例如,单击时组将为红色,子列表将为蓝色。

谢谢

I am searching around about expandable list view in android.
so, we know that there's group-list and child-list...
I want to ask if it's possible, if I want a different drawables
between group and child list, when they're clicked...

e.g.the group will be red and child will be blue when clicked.

Thank you

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

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

发布评论

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

评论(1

农村范ル 2024-11-25 13:49:59

您可以使用 状态列表轻松更改按下的项目的可绘制对象绘图。但是,当子项状态更改时,组项的状态不应自动更改。因此,您的任务是更改组项目状态。

但解决这个任务要小心。列表项由列表适配器呈现,并且该呈现必须基于适配器内项目的状态。因此,在子项单击侦听器中,您应该更改适当的组对象的状态(类似于 group.pressed=true,其中“pressed”是组类的成员)并调用 adapter.notifyDataSetChanged。并在 getView 方法,您应该分析该属性并配置组项可绘制。

You can easily change the drawable for an item that is pressed using state list drawables. But the state of group item should not be changed automatically when the child item state is changed. So it's your task to change the group item state.

But be careful solving this task. List items are rendered by a list adapter and that rendering must be based on the state of items inside the adapter. So, in child items click listener you should change the state of an appropriate group object (something like group.pressed=true, where 'pressed' is a member of your group class) and call adapter.notifyDataSetChanged. And in getView method of the adapter you should analyze that property and configure the group item drawable.

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