我的问题是每当我尝试保存输入的内容时,特别是检查单选组中的适当答案时,其他所有内容都已保存,但未保存组中选定的单选按钮。如果我遗漏了什么,请查看我的代码。这个问题让我发疯已经好几天了。
private void saveData(){
//get entered value and set to a variable
String fname_input = fnametext.getText().toString();
int checkedButton = gendertext.getCheckedRadioButtonId();
//SAVE shared pref value
SharedPreferences.Editor editor = settings.edit();
editor.putString("fname", fname_input);
editor.putInt("gender", checkedButton);
editor.commit();
//show button after saving
Toast.makeText(Profile_Pref.this,
"You have successfully saved!",
Toast.LENGTH_SHORT)
.show();
} // end of saveData method
感谢帮助!
对于我的 loadSavedData 方法: private void loadSavedData(){
//RETRIEVE/load the saved shared pref value
String fname = settings.getString("fname", null);
fnametext.setText( fname );
gendertext.setSelected(true);
} // end of loadSavedData method
我认为这里有一个逻辑错误:(