superseed77
superseed77

Reputation: 213

Expandable List Indicator

I have an expandable list

so two question

  1. (I've seen somme similar question but never found the answer) How do I hide the arrow ( group indicator) when there's no children

    I tried to do it in the adapter

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,ViewGroup parent) {
    if(getChildrenCount(groupPosition)==0) {
          // how do i hide the group indicator ?
    }
    

    But I'm stuck So, how can modify the group indicator for empty groups ?

  2. How to have different behavior when you click on the arrow (expands the group) vs you click on the title of the group (go to an activity)

Upvotes: 6

Views: 4799

Answers (2)

Sahil Mahajan Mj
Sahil Mahajan Mj

Reputation: 11141

Just create a group_indicator.xml file in drawable folder to specify the parent state using the code,

<item android:state_empty="true" android:drawable="@android:color/transparent"></item>
<item android:state_expanded="true" android:drawable="@drawable/arrowdown"></item>
<item android:drawable="@drawable/arrowright"></item>

Then specify this style in the Expandable list view using the code,

<ExpandableListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:groupIndicator="@drawable/group_indicator"
        android:layout_weight="1" >
    </ExpandableListView>

Upvotes: 2

Robby Pond
Robby Pond

Reputation: 73484

  1. You have to set a GroupIndicator drawable with different states. Check out StateListDrawable, maybe for the "state_empty" specify a null drawable.

Upvotes: 4

Related Questions