Generally when we deal with menu’s which are to be show in listview,Sometimes we need to show sub-categories so for this purpose we will deal with android Expandable Listview in name itself says that it will be expanded depending upon categories.

Categories are shown as group headers and sub categories are shown as child items.

 

expandablelistview1

I have shown a ExpandableListview which contains three categories

  1. Sports
  2. Colors
  3. Animals

Which are further sub categorized for example:

expandablelistview2

Creating android ExpandableListviewAdapter File

ExpandableListAdapter.java

 

 

Assigning expandableListView set onClickListener for group click and child click.

MainActivity.java

 

 

Adding ExpandableListView to  activity_main.xml.

activity_main.xml

 

 

Adding parent (Group Header).

 

parent_item.xml

 

 

 

Adding child_item to listview

child_item.xml

 

Output 

device-2016-04-08-164814

Group and Child On Click Toast

 

device-2016-04-08-164849 device-2016-04-08-164932

device-2016-04-08-165109 device-2016-04-08-165233

device-2016-04-08-165311 device-2016-04-08-165355

 

If you have any query’s comment below

Like and share this tutorial if you like it.

Show Buttons
Hide Buttons
Read previous post:
Android Push Notification Tutorial For Beginners

Close