Reputation: 2535
I am using an expandable listview in Navigation Drawer. Now the items in this list are fetched from a webservice - along with the children.
Based on the login type some users only see part of the Navigation drawer. So I have some items with 0 children and I need to detect this condition so that I can redirect on header click to a different page.
Here is my scenario:
I want to get the number of children in a group when the header is clicked. Is this even possible?
So far I have tried this, but the result are not proper:
@Override
public void onDrawerHeaderSelected(ExpandableListView parent, View v, int groupPosition, long id) {
switch (groupPosition) {
case 1:
if (parent.getChildCount() == 0)
displayFragment(groupPosition);
break;
case 2:
if (parent.getChildCount() == 0)
displayFragment(groupPosition);
break;
default:
displayFragment(groupPosition);
}
}
parent.getChildCount()
seems to give me a total nmber of visible children.
Upvotes: 2
Views: 3712
Reputation: 1565
Use setOnGroupClickListener
and in onGroupClick
check your condition using the list of data that you already have and display fragment and return true.
To find group child count -
adapter.getChildrenCount(groupPosition)
Upvotes: 5
Reputation: 157437
use the Adapter.
ExpandableListAdapter adapter = parent.getExpandableListAdapter()
and trough adapter you can access getChildrenCount
and getGroupCount()
Upvotes: 5