2017-04-01 5 views
1

私はrecyclerviewリストにデータを設定し、ラジオグループとテキストのラジオボタンを使用してデータを表示しているアプリケーションを作成します。ラジオボタンをチェックすることができますが、そのアクティビティを再び開くと、チェックされたラジオボタンはチェックされません私は私が再び活動を開くとき私のラジオボタンshouldeがチェックされることを望む。 uは活動の焦点を持っていませんRadioButtonをオンに設定する返信

protected void onResume() { 
    super.onResume(); 
    try { 
     adapter.lastCheckedRB.setChecked(true); 
     } 
     adapter.notifyDataSetChanged(); 
    } catch (NullPointerException e) { 

    } 
} 

答えて

0

ので:

holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) { 
       RadioButton checked_rb = (RadioButton) group.findViewById(checkedId); 
        holder.radioButton.setChecked(true); 

       if (lastCheckedRB != null) { 
        lastCheckedRB.setChecked(false); 
       } 
       if(selectedId!=0) 
       { 
        holder.radioButton.setChecked(true); 
       } 

       //store the clicked radiobutton 
       if(holder.radioButton.isChecked()) 
       { 
        teamList.clear(); 
        lastCheckedRB = checked_rb; 
        teamList.add(name); 

        int checkedIndex = group.indexOfChild(checked_rb); 
       } 
       else 
       { 
        holder.radioButton.setChecked(false); 
       } 
       int selectedId = holder.radioGroup.getCheckedRadioButtonId(); 

      } 

はここに私のActivityクラスです:

は、ここに私のアダプタクラスです。 https://lh6.googleusercontent.com/-cRgfIY8Y0pE/ToyPWqE3L4I/AAAAAAAAAbM/mfpvj5yabiA/s800/20111005_L0023_L_StatesSchema.jpg

+0

私の流れは正しいです、そして私は最後にチェックされた項目を得ることができますが、ラジオボタンをチェックすることができません – sss

関連する問題