我可以在保存的首选项中保存字符串,但无法保存单选按钮。
public class PersonalDetailsf extends Activity {
private SharedPreferences sharedPreferences;
private RadioGroup radioGroup;
private RadioButton radioSexButton;
private RadioButton rdoMale;
Run Code Online (Sandbox Code Playgroud)
这是我的创建:
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);
Run Code Online (Sandbox Code Playgroud)
这是在按钮后面的 onCLick 中,我在其中使用单选按钮并保存字符串:
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) …Run Code Online (Sandbox Code Playgroud)