0

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
hukhan
  • 110
  • 1
  • 2
  • 8
  • Possible duplicate. See http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values – Brad Brown Apr 25 '15 at 20:20
  • @BradBrown My Question is how to store "multiple Radio group". And yours is just about sharedprefrence. – hukhan Apr 25 '15 at 20:25
  • If you want to save and restore information that is done either with a database or with a shared preference. You would parse out the values and store them accordingly. – Brad Brown Apr 25 '15 at 20:26

1 Answers1

0

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),""));
  }
 }
dora
  • 2,047
  • 3
  • 18
  • 20
  • Yes but how will I use sharedprefrence to store multiple status of different radio group in same activity. – hukhan Apr 25 '15 at 20:26
  • I want to store multiple status in same sharedpreference, so how will i store it? – hukhan Apr 25 '15 at 20:28