I am a beginner and facing a problem where I am creating a ListView
with two RadioButton
s and a TextView
. Everything goes fine, but wh
You adapter is always recreating the item for the list view. When he does that, he takes a "fresh" view and you have to set the data to this view using your array.
In your case, if you want to "save" the state of the radio button, you have to save this data as part of the adapter data, meaning in the array.
I suggest you add a field to your Option
object and use it save the last value of the radio button. afterwards, when they line Option option = data[position];
is being called, you can then reclaim the last value and display it on screen.
Add to your adapter 2 abstract function below;
@Override
public int getCount() {
return data.size(); // size, lenght, count ...?
}
@Override
public Object getItem(int position) {
return position;
}
You need to save the state of RadioButton for each item, so while scrolling in getView() method first it will check the state of each RadioButton.
Step1:- You need to create a Pojo class(Setter & Getter) for saving the state of RadioButton.
For more details go through the below link
http://amitandroid.blogspot.in/2013/03/android-listview-with-checkbox-and.html
This example is a ListView with CheckBox you need to change it to RadioButton according to your requirement.