0

I have a radio button group when am checking one of the button it will show as checked. But when I move to other screens and come back none of the buttons will be checked. What I have to do to check the radio button constantly in android.

Midhun VP
  • 629
  • 1
  • 10
  • 18
  • See: http://stackoverflow.com/questions/7334106/how-to-show-that-the-radio-button-is-selected-permanently – Alex Florescu Mar 05 '12 at 13:31
  • 1
    You have to save the status of the radio button in shared pref or in local db and when coming back check the saved data and then set to the radio button – Triode Mar 05 '12 at 13:34

2 Answers2

0

What you need to do is save the state of the page / screen and repopulate it when you navigate back to it. In order to save the state in a global variable, look at this answer.

Android: How to declare global variables?

and when you come back to the page / screen, just check if you have anything saved in the global variable and if yes, then repopulate the values of the radio button.

Community
  • 1
  • 1
Ali Khalid
  • 1,345
  • 8
  • 19
0

SharedPreferences pref = getSharedPreferences("preferencesName", MODE_PRIVATE);

final SharedPreferences.Editor prefEdit = pref.edit();

RadioButton radio = (RadioButton) findViewById(R.id.radio);

radio.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    prefEdit.putBoolean("booleanValue", isChecked).commit();

}

});

Midhun VP
  • 629
  • 1
  • 10
  • 18