简体   繁体   中英

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 . You need to make your own class that extends BaseExpandableListAdapter and use that to create the entries in your list. 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. You can inflate an xml layout or just build one in code right there and return it. It's really no different than using a normal 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 . I think that should work. Let me know what you find.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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