Android ListView RadioButton

Android ListView RadioButton

In previous article  we learnt about how to use multiple choices in ListView. Today we are going to learn how to enable single choice/radio button in ListView, GridView and in RecyclerView using RadioButton, you’ll configure the ListView to display a radioButton next to each item. You can combine many components like TextView, RadioButton, 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 single choice/radio button in ListView, GridView and in RecyclerView using RadioButton.

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 two buttons for implementing actions over selected row.
6. Now lets create java classes for all the above three xml files.

  • ListViewFragment.java
  • GridViewFragment.java
  • RecyclerViewFragment.java
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 to select row is:
8. Finally all things done. Now you can also make your any type of single 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)