title: Android RadioButton only selected after first touch
body: <p>I am writing a quiz program. It has an activity with two fragment. The first is a recycler view of the questions along the side. The second fragment contains a webview and 4 radiobuttons that exist in a radiobutton group. Looks like this:
  <a href="http://i.stack.imgur.com/2P1wy.png" rel="nofollow">Screenshot</a></p>
  
  <p>When a radiobutton is pressed one of the actions taken is to use a callback to alert the recycler view to select a checkbox on the question item in the list to show that it has been answered.</p>
  
  <p>But I've found that making the callback makes the radiobutton group not update the selected radiobutton <strong>on the first press only</strong>. On all subsequent touches radiobuttons update appropriately. I have stripped down my code to the barebones to find this problem and it seems to be the callback, but i really don't understand the issue. I have tried clearCheck() on the button group and setting the checked radiobutton manually. Neither has solved the problem.</p>
  
  <p>I'm including code. OnCreateView in question fragment containers a listener. The listener calls updateDatabaseWithAnswer. updateDatabaseWithAnswer calls a callback to the main Activity that then tells the recyclerview in the other fragment to update. With the code as is, the recyclerView does update correctly and no errors are thrown.</p>
  
  <p>The only way to fix this problem is by commenting out the second line of the callback (see comment in callback function). When that line is commented out the radiobuttons work correctly. </p>
  
  <pre><code>//QuestionFragement - contains radiobuttons and radiogroup
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
      v = inflater.inflate(R.layout.fragment_question, container, false);
      //answerButtonGroup
      mAnswerButtonGroup =(RadioGroup)v.findViewById(R.id.answerButtonGroup);
      mAnswerButtonGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  
          public void onCheckedChanged(RadioGroup group, int checkedId) {
              updateDatabaseWithAnswered();
          }
      });
      return v;
      }
  
  private void updateDatabaseWithAnswered(){
      int id = mQuestion.getId();
      int answerCorrect = 0; //0 = false, 1 = true
      if (mQuestion.getUserAnswer().equals(mQuestion.getCorrectAnswer())){
          answerCorrect = 1;
      }
      mQuestion.setTimesUsed(mQuestion.getTimesUsed() + 1);
      mQuestion.setTimesCorrect(mQuestion.getTimesCorrect() + answerCorrect);
      updateQuestion();
  }
  
  private void updateQuestion(){
      ExamLab.get(getActivity()).updateDatabaseQuestionAnswered(mQuestion);
      //COMMENTING OUT THE FOLLOWING LINE OF CODE FIXES THE RADIOBUTTON PROBLEM
      mCallbacks.onQuestionUpdated(mQuestion, 0);
  }
  
  //ExamListActivity
  /*
  // Interface for QuestionFragment.Callback
   */
  public void onQuestionUpdated(Question question,int changeSelectedQuestion){
      ExamListFragment listFragment = (ExamListFragment) getSupportFragmentManager()
              .findFragmentById(R.id.fragment_container);
      listFragment.updateUI(changeSelectedQuestion);
  }
  
  //ExamListFragment - contains recyclerView
  public void updateUI(int changeSelectedQuestion){
      ExamLab examLab = ExamLab.get(getActivity());
      List&lt;Question&gt; questions = examLab.getQuestions();
  
      if (mAdapter == null){
          mAdapter = new QuestionAdapter(questions);
          mExamRecyclerView.setAdapter(mAdapter);
          /*mAdapter.changeSelectedItem(changeSelectedQuestion);
          mAdapter.notifyDataSetChanged();*/
      }
      else {
          mAdapter.changeSelectedItem(changeSelectedQuestion);
          mAdapter.notifyDataSetChanged();
      }
  }
  </code></pre>