Skip to content

mooqoo/ExpandableListView_Sample

Repository files navigation

ExpandableListView_Sample

This project explore the different ways to create an expandable listview and how they are implemented.

In this project, I use the ExpandableListView provided by Android API and also ExpandableRecyclerViewcreated by bignerdranch.

I use a SlidingTabLayout to display each expandable list inside its own Fragment. To see how to implement a SlidingTabLayout, you can take a look at my SlidingTabLayout sample.

Here's what the project looks like: app layout app layout

ExpandableListView

this is a tutorial for ExpandableListView.

xml

  1. create a layout xml that contains ExpandableListView.
  2. create a xml for the list group item for ExpandableListView.
  3. create a xml for the list child item for each individual group of ExpandableListView.

data

  1. create a list for parent group.
  2. create a list for each child group.
  3. create a new HashMap to associate each child list with its corresponding parent item.

ExpandableListAdapter

In order to build your own Custom Expandable List Adapter, create your own adapter and extends BaseExpandableListAdapter.

  1. pass data to adapter through constructor.
  2. inflate the view for parent in getGroupView.
  3. inflate the view for child in getChildView.
  4. implement all the method from BaseExpandableListAdapter.

Setup ExpandavleListView

  1. get the ExpandavleListView instance from xml.
  2. load/init data for ExpandableListView.
  3. init CustomExpandableListAdapter with data.
  4. set the adapter for ExpandavleListView.
  5. set clickListener and collapse/expand Listener for ExpandavleListView.

ExpandableRecyclerView

ExpandableRecyclerView is a library written to allow for an expanded view to be attached to each ViewHolder. To allow for full functionality of a normal RecyclerView, the RecyclerView has been modified to use two types of ViewHolders, a child and a parent with the ability to customize each separately.

How to use

  1. add dependencies to app's build.gradle file
  2. create xml for parent/child list item layout
  3. create ViewHolder for parent/child class which extends ParentViewHolder/ChildViewHolder
  4. create ParentObject which implements the ParentListItem
  5. create CustomExpandableRecyclerAdapter by extending ExpandableRecyclerAdapter<MyParentViewHolder, MyChildViewHolder>
  6. get instance for RecyclerView and set the layoutManager and adapter.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages