Reputation: 14658
Is there a way to show expandable and non expandable list in the same list view? What I am trying to achieve is to have expandable list view but for items that don't have sub items, and I don't want to show the arrow expand arrow icon How how can I do that? Please help Thanks
EDIT: All what I want is to be able to hide indicator arrow when group is empty
Upvotes: 0
Views: 743
Reputation: 2898
1) Basically, you have to hide "expand arrow" when group has no child.
You can achieve this by setting GroupIndicator
property to null.
For ex : getExpandableListView().setGroupIndicator(null);
OR
2) by checking the children count you can set the indicator like the below code,
if ( getChildrenCount( groupPosition ) == 0 ) {
indicator.setVisibility( View.INVISIBLE );
} else {
indicator.setVisibility( View.VISIBLE );
indicator.setImageResource( isExpanded ? R.drawable.list_group_expanded : R.drawable.list_group_closed );
}
For more information about hiding Group indicator, you can refer this link.
OR
3) Create a group_indicator.xml file in drawable folder
<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, define expandable list view like the below 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>
Hope this will solve your problem.
Upvotes: 1
Reputation: 21
Yes. you can.
this class has next methods: getGroupTypeCount() and getGroupType(int groupPosition)
which you should override.
In simple way you have two type of item. For example Expandable(type 1) and Not expandable(type 2).
getGroupTypeCount() shoul return 2;
override getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) in this method check item's type by item's position. If item not expandable you should generate View which its look doesn't depend of if it is expanded or not.
I think it is very simple.
Upvotes: 1