Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expandable List Indicator

Tags:

android

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)

like image 852
superseed77 Avatar asked Jul 06 '10 19:07

superseed77


2 Answers

  1. You have to set a GroupIndicator drawable with different states. Check out StateListDrawable, maybe for the "state_empty" specify a null drawable.
like image 188
Robby Pond Avatar answered Sep 20 '22 17:09

Robby Pond


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>
like image 32
Sahil Mahajan Mj Avatar answered Sep 21 '22 17:09

Sahil Mahajan Mj