简体   繁体   English

带有父级和子级图标的可扩展Listview

[英]Expandable Listview with icons for parent and child

I am trying to create an expandable listview similar to the expandable list shown here 我正在尝试创建类似于此处显示的可扩展列表的可扩展列表视图

Are there any examples which would help me achieve this. 是否有任何示例可以帮助我实现这一目标。

Thr parent and child data I have would be static always. 我拥有的父级和子级数据始终是静态的。

I use this as my reference. 以此为参考。 Can any expert kindly guide me as to what code snippet I need to add to this, so that I can set icons for both parent and child. 任何专家都可以请我指导需要添加哪些代码段,以便为父母和孩子设置图标。

Any help in this regard will be well appreciated. 在这方面的任何帮助将不胜感激。

Regards, Rony 问候罗尼

In that example that you say you use as a reference there is a class called ExpandableListAdapter . 在该示例中,您说您用作参考,有一个称为ExpandableListAdapter的类。 You need to make your own class that extends BaseExpandableListAdapter and use that to create the entries in your list. 您需要创建自己的扩展BaseExpandableListAdapter的类,并使用该类在列表中创建条目。 The two methods you will need to focus on to change the layout of the entries are: 更改条目布局所需的两种方法是:

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)

and

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)

In both of these in the example they call getGenericView() which just returns a TextView , but you can do anything you want. 在这两个示例中,它们都调用getGenericView() ,该方法仅返回TextView ,但是您可以执行任何操作。 You can inflate an xml layout or just build one in code right there and return it. 您可以膨胀xml布局,也可以直接在其中构建代码并返回。 It's really no different than using a normal ListAdapter . 与使用常规ListAdapter确实没有什么不同。

If you want to override the default expanded indicator you can create your own stateful drawable like this: 如果要覆盖默认的扩展指示器,则可以创建自己的有状态可绘制对象,如下所示:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_expanded="true"
        android:drawable="@drawable/expander_ic_maximized" />
    <item
        android:drawable="@drawable/expander_ic_minimized" />
</selector>

and put that where ever you want in your layout and give it the id of @android:id/groupIndicator . 并将其放置在布局中所需的任何位置,并为其提供@android:id/groupIndicator I think that should work. 我认为应该可以。 Let me know what you find. 让我知道你发现了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM