I have an expandable list that I am creating using a custom adapter class extending BaseExpandableListAdapter
. Is there a way for me to add an empty view child under each of the groups in my expandable list when there are no items in that group?
EDIT:
I tried to use mExpList.setEmptyView(getActivity().findViewById(R.id.empty_child));
but it did not work. R.id.empty_child
is in the same xml right below the expandable list view.
call its method ExpandableListView. OnChildClickListener inside that get count of child by passing groupPosition that will return count of childs related to the groupPosition you pass.
android.widget.ExpandableListView. A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view.
A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.
An adapter links an Android ExpandableListView with the underlying data. The implementation of this interface will provide access to the data of the children (categorized by groups), and also instantiate Views for children and groups.
This ArrayAdapter is filled with items as defined in Strings.xml as string-array. After filling Spinner, we are adding products one by one in Expandable list view through addProduct (). In the addProduct (), we are first checking if product is already present. If it's not, then it is added to the corresponding category.
The implementation of this interface will provide the data for the children and also initiate the views for the children and groups. For customization of List we need to implement ExpandableListAdapter in our custom Adapter.
Here, we will make a custom ExpandablelistView where a user can add data in the menu and can even add a new category. For adding new category, we will use a dropdown Spinner and a search button will be used to add products in that category.
In the getChildView() method, you can determine if that group has any children. If there aren't any, you can return an Empty View.
At the same time, you will need to adjust the other related methods like, getChildrenCount(), getChild() etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With