title: How to get values of radio group from listview?
body: <p>I am developing Android Attendance application, in which teacher can take attendace.<a href="http://i.stack.imgur.com/Q4ibw.jpg" rel="nofollow">Here is the image</a>. I have taken example from <a href="http://amitandroid.blogspot.in/2013/03/android-listview-with-radiongroup-and.html" rel="nofollow">here</a>. But i am not getting, how do i get the values of radio button when SUBMIT button is clicked.</p>
  
  <p>Attendance.class</p>
  
  <pre><code>public class Attendance extends Activity {
  
      private ListView listView1;
      Button submit;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.attendance);
          submit = (Button) findViewById(R.id.testbutton);
  
          Option weather_data[] = new Option[]
                  {
                          new Option("Student1"),
                          new Option("Student2"),
                          new Option("Student3"),
                          new Option("Student4"),
                          new Option("Student5"),
                          new Option("Student6")
  
                  };
          RadioGroupAdapter adapter = new RadioGroupAdapter(this,
                  R.layout.listitem, weather_data);
          listView1 = (ListView)findViewById(R.id.list);
          listView1.setAdapter(adapter);
      }
  
  
  
  }
  </code></pre>
  
  <p>RadioGroupAdapter.class</p>
  
  <pre><code>public class RadioGroupAdapter extends ArrayAdapter&lt;Option&gt; {
  
      Context context;
      int layoutResourceId;
      Option data[] = null;
  
      public RadioGroupAdapter(Context context, int layoutResourceId,
                               Option[] data) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          MatrixHolder holder = null;
  
          if (row == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, parent, false);
  
              holder = new MatrixHolder();
              holder.txtTitle = (TextView) row.findViewById(R.id.heading);
              holder.group = (RadioGroup) row.findViewById(R.id.radio_group1);
              final RadioButton[] rb = new RadioButton[2];
              for(int i=0; i&lt;2; i++){
                  rb[i]  = new RadioButton(context);
                  //rb[i].setButtonDrawable(R.drawable.single_radio_chice);
                  rb[i].setId(i);
                  RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
                          0, LayoutParams.WRAP_CONTENT);
                  params.weight=1.0f;
                  params.setMargins(5, 0, 5, 10);
                  holder.group.addView(rb[i],params); //the RadioButtons are added to the radioGroup instead of the layout
              }
              row.setTag(holder);
          } else {
              holder = (MatrixHolder) row.getTag();
          }
  
          Option option = data[position];
          holder.txtTitle.setText(option.title);
          return row;
      }
  
      static class MatrixHolder {
          TextView txtTitle;
          RadioGroup group;
          int position;
      }
  }
  </code></pre>
  
  <p>option.class</p>
  
  <pre><code>public class Option {
      public String title;
      int selectedId=-1;
      public Option(){
          super();
      }
  
      public Option( String title) {
          super();
          this.title = title;
  
      }
  
  }
  </code></pre>
  
  <p>Logcat</p>
  
  <pre><code>05-17 13:17:13.254 5141-5141/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: org.pitechnologies.teacher, PID: 5141
                                                   java.lang.IllegalStateException: Could not execute method of the activity
                                                       at android.view.View$1.onClick(View.java:4020)
                                                       at android.view.View.performClick(View.java:4780)
                                                       at android.view.View$PerformClick.run(View.java:19866)
                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                       at android.os.Looper.loop(Looper.java:135)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at android.view.View$1.onClick(View.java:4015)
                                                       at android.view.View.performClick(View.java:4780) 
                                                       at android.view.View$PerformClick.run(View.java:19866) 
                                                       at android.os.Handler.handleCallback(Handler.java:739) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                       at android.os.Looper.loop(Looper.java:135) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.pitechnologies.teacher.Option[] org.pitechnologies.teacher.RadioGroupAdapter.getItems()' on a null object reference
                                                       at org.pitechnologies.teacher.Attendance.onClick(Attendance.java:40)
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at android.view.View$1.onClick(View.java:4015) 
                                                       at android.view.View.performClick(View.java:4780) 
                                                       at android.view.View$PerformClick.run(View.java:19866) 
                                                       at android.os.Handler.handleCallback(Handler.java:739) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                       at android.os.Looper.loop(Looper.java:135) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  </code></pre>