我有一个问题,要记住EditText和RadioButtons的值我添加@onResume和@onPause方法,它适用于编辑文本,但问题是单选按钮出现检查但是当我点击将值注册到数据库,我有消息(没有检测到值),我该怎么做才能解决问题?有解决方案!!!
@Override
protected void onPause()
{
super.onPause();
SharedPreferences prefs3 = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs3.edit();
editor.putBoolean("questionA", rm_13_1.isChecked());
editor.putBoolean("questionB", rm_13_2.isChecked());
editor.putBoolean("questionC", rm_14_1.isChecked());
editor.putBoolean("questionD", rm_14_2.isChecked());
editor.putBoolean("questionE", rm_14_3.isChecked());
// Commit the edits!
editor.commit();
}
@Override
protected void onResume(){
super.onResume();
SharedPreferences prefs3 = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
rm_13_1 = (RadioButton)findViewById(R.id.rm_13_1) ;
rm_13_2 = (RadioButton)findViewById(R.id.rm_13_2);
rm_14_1 = (RadioButton)findViewById(R.id.rm_14_1) ;
rm_14_2 = (RadioButton)findViewById(R.id.rm_14_2);
rm_14_3 = (RadioButton)findViewById(R.id.rm_14_2);
Boolean rm_13_1A = false;
Boolean rm_13_2A = false;
Boolean rm_14_1A = false;
Boolean rm_14_2A = false;
Boolean rm_14_3A = false;
rm_13_1A = prefs3.getBoolean("questionA",false);
rm_13_2A = prefs3.getBoolean("questionB",false);
rm_14_1A = prefs3.getBoolean("questionC",false);
rm_14_2A = prefs3.getBoolean("questionD",false);
rm_14_3A = prefs3.getBoolean("questionE",false);
rm_13_1.setChecked(rm_13_1A );
rm_13_2.setChecked(rm_13_2A );
rm_14_1.setChecked(rm_14_1A );
rm_14_2.setChecked(rm_14_2A );
rm_14_3.setChecked(rm_14_3A );
}
答案 0 :(得分:1)
pref=PreferenceManager.getDefaultSharedPreference(this)
试