title: Getting the check changed event for a dynamically created Radio Group within a ListView
body: <p>We are working on a project where there is a questionnaire with dynamically created radio groups with radio buttons.At the bottom of the listview we have placed a button and we need the selected values from the radio buttons on clicking the button.<strong>The issue is how to get the selected Radio button values.Also i wanted to know in which class i can get the values in the main activity or in the Base Adapter class?</strong></p>
  
  <p>We have done the following:</p>
  
  <p>The main activity:</p>
  
  <pre><code>submit.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  for(m=0;m&lt;question_list_array.size();m++)
                  {
  
  
                          View view= question_list.getChildAt(m);
                          RadioGroup radioGroup= (RadioGroup) view.findViewById(R.id.single_radiogroup);
                          radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                              @Override
                              public void onCheckedChanged(RadioGroup group, int checkedId) {
                                  for(int n=0;n&lt;group.getChildCount();n++)
                                  {
                                      RadioButton rb= (RadioButton) group.getChildAt(n);
                                      if (rb.getId() == checkedId) {
                                          String result= rb.getText()+"";
                                          Toast.makeText(MainActivity.this,result, Toast.LENGTH_LONG).show();
                                          // do something with text
                                          return;
                                      }
                                  }
                              }
                          });
  
                      }
  
                  }
  
  
          });
  </code></pre>
  
  <p>But i am getting NPE at the following line:</p>
  
  <pre><code>RadioGroup radioGroup= (RadioGroup) view.findViewById(R.id.single_radiogroup);
  </code></pre>
  
  <p>The adapter class:</p>
  
  <pre><code>@Override
      public View getView(int position, View convertView, ViewGroup parent) {
          String question_type = question_list_array.get(position).getQuestion_type();
          option_list = question_list_array.get(position).option_list;
          number_of_options = option_list.size();
  
  
  
              v_single=convertView;
              if (v_single == null) {
                  v_single = inflater.inflate(R.layout.single_choice_layout, null);
                  sh = new SingleHolder();
                  sh.single_question_name = (TextView) v_single.findViewById(R.id.single_question_name);
                  sh.single_radiogroup = (RadioGroup) v_single.findViewById(R.id.single_radiogroup);
                  v_single.setTag(sh);
  
              }
              else
              {
                  sh = (SingleHolder) v_single.getTag();
              }
              sh.single_radiogroup.clearCheck();
              sh.single_radiogroup.removeAllViews();
              sh.single_question_name.setText(question_list_array.get(position).getQuestion_name());
              for (int j = 0; j &lt; number_of_options; j++)
              {
                  RadioButton rb = new RadioButton(context);
                  rb.setText(option_list.get(j).getOption_name());
                  sh.single_radiogroup.addView(rb);
              }
         v_final=v_single;
  
  
          return v_final;
      }
  </code></pre>
  
  <p>We dont have any issues with the Adapter as such.Please reply at the earliest.</p>