Android 检查单选按钮缺失值

Android 检查单选按钮缺失值,android,Android,我有一个问题,为了记忆EditText和单选按钮的值,我添加了@onResume和@onPause方法,这对编辑文本很好,但问题是单选按钮显示为选中状态,但当我单击将值注册到数据库中时,我收到一条消息(未检测到值),我应该如何解决该问题?有解决办法吗 @Override protected void onPause() { super.onPause(); SharedPreferences prefs3 = getSharedPreferences(PREFS_NAM

我有一个问题,为了记忆EditText和单选按钮的值,我添加了@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 );

     }

试试看

谢谢您的回复,我应该在哪里写这篇文章,我不应该删除其他pref?!!为此更改您的首选项
pref=PreferenceManager.getDefaultSharedPreference(this)