I am working on an app which have multiple Radio Groups.
I want to save their checked status and restore it on next restart.
So which is be the most efficient way to do that?
I am working on an app which have multiple Radio Groups.
I want to save their checked status and restore it on next restart.
So which is be the most efficient way to do that?
I think you need to use SharedPreferences to store the checked items in the radio groups because they will be present unless we uninstall the app.
To store value's in shared preferences
List<RadioGroup> radioGroups;
List<String> savedids;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("number of radio groups", radiogroupsCount);
for(int i=0; i< radiogroupsCount; i++){
editor.putString("radioGroup"+String.valueOf(i), radioButtonGroup.getCheckedRadioButtonId(););
}
editor.commit();();
To retrieve values from shared preferences:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String count = preferences.getString("number of radio groups", 0);
if(count >=0){
for(int i=0; i < count; i++){
savedIds.add(preferences.getString("radioGroup"+String.valueOf(i),""));
}
}