title: how to get data of selected multiple radio button values from a Radio Group in android when a button is clicked
body: <p>how to get data of selected  multiple radio button values from a Radio Group in android when a button is click ..and display all the data..Code is working but stuck on ..when a button is submit and not getting the data.</p>
  
  <p>here is the code:</p>
  
  <pre><code>import android.os.Bundle;
  import android.app.Activity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.RadioGroup.OnCheckedChangeListener;
  import android.widget.RelativeLayout;
  
  public class Main9Activity extends Activity {
      RadioGroup RG1,RG2,RG3;
      RelativeLayout rl;
      public String chec="";
      Button bt;
  
  
      String status[] = { "Leave", "Late", "Absent", "Present" };
     // RadioGroup rg;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main9);
          LinearLayout rl = (LinearLayout) findViewById(R.id.linear1);
         // rl = (RelativeLayout) findViewById(R.id.linear1);
  
  
  
  
  
          for (int k = 1; k &lt; 4; k++) {
              final RadioButton[] rb = new RadioButton[10];
  
             // rg = new RadioGroup(this);
              final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
              rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
              final TextView name=new TextView(this);
              String texid="16roll"+k;
              name.setText("16roll"+k);
              name.setId(R.id.RG2+k);
  
              int n = 4;
              for (int i = 0; i &lt; n; i++) {
                  rb[i] = new RadioButton(this);
                  rg.addView(rb[i]);
                 // rb[i].setText("Radio " + i);
                  rb[i].setText(status[i]);
  
              }
              //rl.addView(rg);
  
              rl.addView(name);
              rl.addView(rg);
              rl.setPadding(50, 50, 50, 50);
              rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                  @Override
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
  // TODO Auto-generated method stub
                      int pos = rg.indexOfChild(findViewById(checkedId));
                      //String roll="ytutyuty";
                      String roll=name.getText().toString();
                      switch (pos) {
                          case 0:
  
                              Toast.makeText(getBaseContext(),  String.format("Leave" + roll), Toast.LENGTH_SHORT).show();
  
                              chec="Leave"+ roll;
                              break;
                          case 1:
                              Toast.makeText(getBaseContext(), String.format("Late" +roll), Toast.LENGTH_SHORT).show();
                              chec="Late" +roll;
                              break;
                          case 2:
                              Toast.makeText(getBaseContext(), String.format("Absent" +roll), Toast.LENGTH_SHORT).show();
                              chec="Absent" +roll;
                              break;
                          default:
                              Toast.makeText(getApplicationContext(), String.format("Present" +roll), Toast.LENGTH_SHORT).show();
                              chec="Present" +roll;
                              break;
                      }
                  }
              });
          }
         // Toast.makeText(getBaseContext(),  String.format(chec), Toast.LENGTH_SHORT).show();
          //  @Override
          //public boolean onCreateOptionsMenu(Menu menu) {
          // getMenuInflater().inflate(R.menu.activity_main, menu);
          // return true;
          // }
  
  
          bt= (Button) findViewById(R.id.button2);
          bt.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Toast.makeText(getBaseContext(),  String.format(chec), Toast.LENGTH_SHORT).show();
                  //
              }
          });
  
  
      }
  }
  </code></pre>