Monday 16 January 2017

Android Expandable ListView / ExpandableListView

ExpandableListView is kind of advanced version of Listview. You can expand the list items. It is very useful when you have categories and sub categories of data. Here a tutorial using for ExpandableListView with event listener of parent and child list items.


All you need to do is to follow the simple steps
  • Create main_activity.xml.
  • Create list_group.xml
  • Create list_item.xml.
  • Create the ExpandableListAdapter.java.
  • Create MainActiviy.java.
In ExpandleListAdapter.java, you need to add the @Override some methods of BaseExpandableListAdapter class. important methods are getGroupView and getChildView. In these methods, you need to hook the (in our example) TextView and ImageView of the main list and sublist respectively.

The file main_activity.xml contain the ExpandableListView tag. list_item.xml and list_gruop.xml has the TextViews for list and sublist.

You can get the complete project at Github Repository. Or you can get the code below in this post.

Here is you main_activiy.xml
list_group.xml
list_item.xml
ExpandableListAdapter.java
MainActivity.java

3 comments:

  1. Really a great and simple tutorial for beginners. Thumbs up (Y)

    ReplyDelete
  2. Your content is excellent but with pics and videos,
    this blog could certainly be one of the best in its field.
    Excellent blog!
    KissAnime

    ReplyDelete