Overview
I have a List of items in my list view. When any item is clicked then next activity is started and in that activity there are few edit texts and three radio buttons in a radio group. I named these radio buttons as 'present','absent' and 'transfer'.
Problem and what I want to achieve
Now I managed to save the state of radio buttons so that if any of the radio button is checked and then activity closes then the radio button state will be saved. But my Problem is that whenever the value is stored when activity closes, all the list view items change their radiobutton states to that saved state.
Problem Explanation with Example
Lets say i have three items which are teachers in my list view. A, B and C. When i click on item A then activity named 'Attendance' started. Similarly when i clicked on B or C then activity Attendance started.Now if I click on item A and mark the attendance as Present and saved the state then when ever i open the item B or item C it will show me Present although i haven't change the value in item B or C. I just stored the value for item A but it also show changes in item B and C. I don't know what to do in this case to save radiobutton state for each listview item
What I Tried
This is what I am doing in my Oncreate method in Attendance activity.
SharedPreferences settings = getSharedPreferences("answers", MODE_PRIVATE);
boolean r2achecked = settings.getBoolean("r2a",false);
boolean r2bchecked = settings.getBoolean("r2b",false);
boolean r2cchecked = settings.getBoolean("r2c",false);
if (r2achecked == true)
{
one.setChecked(true);
}
else if (r2bchecked == true)
{
two.setChecked(true);
}
if (r2cchecked == true)
{
three.setChecked(true);
}
and I am saving the states of radio buttons here in Attendance activity
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences settings = getSharedPreferences("answers", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("r2a",one.isChecked());
editor.putBoolean("r2b",two.isChecked());
editor.putBoolean("r2c",three.isChecked());
editor.apply();
finish();
}
Please Help anyone