单击时将不同的可绘制对象设置为组和子列表
我正在搜索有关 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 状态列表轻松更改按下的项目的可绘制对象绘图。但是,当子项状态更改时,组项的状态不应自动更改。因此,您的任务是更改组项目状态。
但解决这个任务要小心。列表项由列表适配器呈现,并且该呈现必须基于适配器内项目的状态。因此,在子项单击侦听器中,您应该更改适当的组对象的状态(类似于 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.