Android ExpandableListView Checkbox Example Handle Multiple Selection

Android ExpandableListView Checkbox Example is covered in this post.

We will put checkboxes in the child rows of expandable listview.

We will solve the general problems like

  1. checkbox gets unchecked while scrolling the listview
  2. Different positioned or multiple checkboxes are checked when click on single box

First, see the output of the tutorial then we will develop it step by step.

Download Source Code For Android Expandablelistview Checkbox

Click following link and download your source code

Step 1. Create project in Android Studio.

Make a new project in android studio with empty activity as the default activity.

Step 2. Update colors.xml

Update your colors.xml file with following

Step 3. Adding Images

Download Images by Clicking following link

It contains three images,

  1. icon_checked,
  2. icon_unchecked and
  3. icon_dot

Now, put icon_dot into mipmap folder and copy icon_checked and icon_unchecked into drawable folder.

See below image for reference

android expandablelistview checkbox

Step 4. Adding files in drawable

Make a new layout xml named background_bordered_theme.xml and add below source code in it

Now create another layout xml file and give it a name custom_checkbox_theme.xml

Copy below code into it

Prepare third xml file named edit_text_theme.xml

Code for this file is like

Step 5. Making layout resources files

Create a new layout resource xml file in res->layout folder. It will be called child_list_layout_choose_category.xml

It’s code seems like

Make second xml file in res->layout folder and give it sweet name like group_list_layout_choose_categories.xml

Add below code in it

Prepare last xml file in res->layout and gibe its name group_list_layout_my_categories.xml

Step 6. Making Model Classes

Make a new folder called Model in app->java->your package name (It is the same path where your MainActivity is present)

See below image where you need to put required JAVA classes

android expandablelistview checkbox

Create a new JAVA class named DataItem.java in Model folder

Add Code for it like

Make a second Model class named SubCategoryItem.java in Model folder

Add following code in it

Make a new JAVA class named “ConstantManager.java” at the path shown in above image

Code for this class will look like

Prepare another JAVA class named MyCategoriesExpandableListAdapter.java

Add below source code in it

Step 7. Update Main Activity

Finally, update activity_main.xml like below

And replace code of MainActivity.java with following

Now run your project and enjoy playing with checkboxes in expandable listview.

Support us by sharing our tutorials with other learners.

Thanks and have a nice day!

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *