Android ListView Checkbox

Android ListView Checkbox

Hi to all, today we are going to learn how to enable multiple items to be chosen in ListView, GridView and in RecyclerView using CheckBox, you’ll configure the ListView to display a checkbox next to each item. You can combine many components like TextView, CheckBox, ImageView, etc. and can make ListView as you require.

Prerequisite:

  1. Material Tabs Tutorial
  2. ListView Tutorial
  3. GridView Tutorial
  4. RecyclerView Tutorial

Example

In this tutorial, we are going to learn how to enable multiple items to be chosen in ListView, GridView and in RecyclerView using CheckBox.

VIDEO DEMO

1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and fill required details. By default my activity is MainActivity.java.

2. Open build.gradle and include this libraries show below:

3. Now create 3 material tabs naming ListView, GridView and RecyclerView. For this you can check this link for reference.

4. After creating tabs lets move to creating xml layouts for individual tabs.

  • list_view_frament.xml
  • grid_view_fragment.xml
  • recycler_view_fragment.xml
5. In all the above xml layouts i am using one common layout i.e. bottom_container.xml. Lets create the common layout xml, this layout contains three buttons for implementing actions over selected rows.
6. Now lets create java classes for all the above three xml files.

  • ListViewFragment.java
  • GridViewFragment.java
  • RecyclerViewFragment.java
In all the three above Java classes the main thing that we need to focus is button click events:

  • Show Button : This button used to show a Toast of checked rows.
  • Delete Button : This button is to delete checked rows.
  • Select All/Deselect All Button : This button is to select and deselect all the rows.
7. Now after creating all fragment classes we have to create Adapters for ListView, GridView and RecyclerView.

  • GridListAdapter.java
  • RecyclerViewAdapter.java
In both the above adapter the common code is to select rows:
8. Finally all things done. Now you can also make your any type of multiple choice list view.

Thanks. 🙂

Download Source Code – >

About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)