ANDROID - ExpandableListView
我试图弄清楚如何构建一个包含(许多)的视图:
- PARENT1(可检查,可扩展)
- CHILD1(单选按钮)
- CHILD2(单选按钮)
...
- PARENT2(可检查,可扩展)
- CHILD1(可检查)
- CHILD2(可检查)
...
重点是父级必须是可检查的,并且基于子级必须更改图标。有人可以指出我正确的方向吗,因为从我发现的情况来看,似乎没有什么对我有用。
Im trying to figure out how to build a view that contains (many of):
- PARENT1 (checkable, expandable)
- CHILD1 (RADIO BUTTON)
- CHILD2 (RADIO BUTTON)
...
- PARENT2 (checkable, expandable)
- CHILD1 (CHECKABLE)
- CHILD2 (CHECKABLE)
...
The point is that parent has to be checkable and based on that children have to change the icon. Can some1 point me into the right direction, because from what i found nothing seems to work for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设,您的数据以某种方式结构化,例如:
ArrayList 其中
child:ArrayList} 和
如果是这样,您只需要做两件事:
父项渲染器和子项
渲染器
自己建立清单。
以下是我的想法的一个小样本:
layout/grouprow.xml:
layout/childrow.xml:
MyELAdapter 类:我已将其声明为 MyExpandableList 的内部类,所以我可以直接到达父母列表,而不必将其作为参数传递。
您必须已经有一个公共类
MyExpandableList extends ExpandableListActivity
,它有一个成员:在为该成员分配值/加载父级列表后,您还应该将适配器附加到该视图:
就是这样。您有一个可检查可扩展列表,并且在
CheckUpdateListener
的onCheckedChanged(CompoundButton buttonView, boolean isChecked)
方法中,您可以更新父对象的检查状态。请注意,背景颜色是在 getGroupView 方法中确定的,因此您不必在任何地方更改它,只需在需要时调用适配器的
notifyDataSetChanged()
方法即可。更新
您可以从此链接下载示例源代码。这是一个eclipse项目,但如果您使用其他开发环境,只需简单地复制必要的源文件(java + xml)。
I assume, you have your data structured somehow, like:
ArrayList where
children:ArrayList} and
If so, you only have to do two things:
parent item renderer and child item
renderer
build up the list yourself.
Here is a small sample about what's in my mind:
layout/grouprow.xml:
layout/childrow.xml:
MyELAdapter class: I've declared this as an inner class of MyExpandableList, so i could reach the list of parents directly, without having to pass it as parameter.
You must already have a public class
MyExpandableList extends ExpandableListActivity
which has a member:after you assign a value to this member / load the list of parents, you should also attach your adapter to this view:
and that's it. You have a checkable-expandable list, and in the
CheckUpdateListener
'sonCheckedChanged(CompoundButton buttonView, boolean isChecked)
method you can update your parent object's checked state.Note, that the background color is determined in the getGroupView method, so you don't have to change it anywhere, just call the adapter's
notifyDataSetChanged()
method if needed.Update
you can download the sample source code from this link. It is an eclipse project, but if you are using other developer environment, just simply copy the necessary source files (java + xml).