Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty View in Expandable List Adapter

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.

like image 652
nknj Avatar asked Jun 12 '13 07:06

nknj


People also ask

How do you click on a group if a child is empty in expandable ListView android?

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.

What is ExpandableListView in android?

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.

How list view works in android?

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.

What is an adapter in Android expandablelistview?

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.

How to add products in expandable list view using arrayadapter?

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.

What is the use of expandablelistadapter in Java?

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.

How to add a new category to an expandablelistview?

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.


1 Answers

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.

like image 147
Kumar Bibek Avatar answered Oct 02 '22 20:10

Kumar Bibek