Spartan123
Spartan123

Reputation: 103

How Can I Add Different Icons to Child Elements in Expandable ListView?

I have created an Expandable ListView for my app following this tutorial:

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

I'm wanting to add different icons for each child aligned to the right, how can I do this?

Any help is appreciated, thanks

Upvotes: 0

Views: 339

Answers (1)

nikis
nikis

Reputation: 11234

In the list_item.xml from the article you've posted just put the needed drawable on the right of TextView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblListItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17dip"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:drawableRight[End]="@drawable/my_cool_drawable"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
</LinearLayout>

If every item should have different drawable, then just set it in the runtime, by using setCompoundDrawable method:

txtListChild.setCompoundDrawable(null, null, myCoolDrawable, null);

You may want to specify drawablePadding as well. Btw, LinearLayout in the example from the article is useless, you can use FrameLayout instead or even check merge tag.

Upvotes: 1

Related Questions