2017-04-01 71 views
1

創建應用程序,我在其中設置數據在recyclerview列表中,並顯示該數據使用單選按鈕在radiogroup和text.I能夠檢查單選按鈕,但是當我再次打開該活動時,我檢查的單選按鈕未選中,但我希望當我再次打開活動時,我的單選按鈕將被檢查。設置RadioButton檢查onResume

這裏是我的適配器類:

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類:

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

    } 
} 

回答