¿Cómo guardar el estado del botón de opción en las preferencias guardadas / compartidas?
Puedo guardar cadenas en mis preferencias guardadas pero tengo dificultades para guardar los botones de opción.
public class PersonalDetailsf extends Activity {
private SharedPreferences sharedPreferences;
private RadioGroup radioGroup;
private RadioButton radioSexButton;
private RadioButton rdoMale;
Aquí está mi en Crear:
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String strAge = Integer.toString(age);
String strHeight = Integer.toString(height);
String strWeight = Integer.toString(weight);
name = loadSavedPreference("name");
strAge = loadSavedPreference("strAge");
strHeight = loadSavedPreference("strHeight");
strWeight = loadSavedPreference("strWeight");
etName.setText(name);
etAge.setText(strAge);
etHeight.setText(strHeight);
etWeight.setText(strWeight);
Esto está en mi onCLick detrás de un botón, donde estoy usando el botón de radio y guardando las cadenas:
Name = etName.getText().toString();
age = (int) Double.parseDouble(etAge.getText().toString());
height = (int) Double.parseDouble(etHeight.getText().toString());
weight = (int) Double.parseDouble(etWeight.getText().toString());
int selectedId = radioGroup.getCheckedRadioButtonId();
radioSexButton = (RadioButton) findViewById(selectedId);
rdoMale = (RadioButton) findViewById(R.id.rdoMale);
if(rdoMale.isChecked())
{
BMR = 10 * weight + 6.25 * height - 5 * age + 5;
}
else
{
BMR = 10 * weight + 6.25 * height - 5 * age -161;
}
//Save Preferences
String strAge = Integer.toString(age);
String strHeight = Integer.toString(height);
String strWeight = Integer.toString(weight);
name = etName.getText().toString();
savePreference("name",name);
strAge = etAge.getText().toString();
savePreference("strAge",strAge);
strHeight = etHeight.getText().toString();
savePreference("strHeight",strHeight);
strWeight = etWeight.getText().toString();
savePreference("strWeight",strWeight);