Solution To Android Listview Checkbox Scroll Problem

Listview in android is an important widgets in android to display data on it. The android listview is a view which is used to group several item and display them in vertical scrollable list.

In listview each item to be displayed is show by Adapter whose work is to pull the content from array, Linked List, HashMap or Database.

In this tutorial I am going to show you how to use check box on listview. The main problem in listView with checkbox is that the state of checkbox gets lost on scroll. So in this tutorial I am going to show you how to maintain the state of checkbox.

The solution for this problem is very simple i.e is you have to store the states for our checkbox. so without further a do let’s get started.

Creating User Interface

solution to android listview problem

activity_main.xml

Now add the row layout. In every listview the row view is very important thing without this view you are not able to show anything on listview.

row_layout.xml

Building Android Application

  • Define Model class Country.java. This will be used to stored data and also to set data to respective view.

  • Now define the Adapter of listView. Here each row of list is set with UI data.

  • Define the view Object in MainActivity.java. Connect user interface with the main java class so the user can interact with it.

  • Now set the Adapter with data. so that we can set data on each row.

  • Define the MainActivity.java i.e combining whole code in java class.

  • Now run the application.

solution to android listview problem solution to android listview problem solution to android listview problem

That’s all friends. If you are facing any problem then comment below will be ready to help you.

15 thoughts on “Solution To Android Listview Checkbox Scroll Problem”

  1. hey
    i am getting trouble when check box is selected at that time i am setting text but text is not setted. its gets text is randomly check box row
    how to handle set text on paricular check is selected ob that postion

      1. i have 4 radio button, when i select the second radio button in first row and i scroll it is still in the selected. but when i select radio button in another row, the radio button at first row will follow it. Can you tell me how to fix it please? or can you check my code and i will send it to you?

        thanks before

  2. Hi bro… I’m having one problem…Checkbox is unchecked when it is scroll down.. I’m not able to resolve that.. please help me..

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.