title: How to get selected radio button value from question1 activity page to next page
body: <p>i am developing a quiz using mobile application. currently, i am having problems on how to       retrieve selected radio button from previous page. i want the selected radio button value to be displayed on the next page. below is my code in xml and java. </p>
  
  <p>question1. java</p>
  
  <pre><code>public class question1 extends Activity {
      private Button Button2;
      public RadioButton r1,r2,r3;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.question1); 
  
          r1 = (RadioButton)findViewById(R.id.rb1);
          r2 = (RadioButton)findViewById(R.id.rb2);
          r3 = (RadioButton)findViewById(R.id.rb3);
  
          //Button2
          Button2 = (Button) findViewById(R.id.button1);
          Button2.setOnClickListener((new OnClickListener() {                 
              public void onClick(View view) {
                  Intent intent = new Intent(view.getContext(),question2.class);
                  intent.putExtra("r1",r1.isSelected());
                  intent.putExtra("r2",r2.isSelected());
                  intent.putExtra("r3",r3.isSelected());
                  startActivityForResult(intent,0);               
              }
          }));
      }
  } 
  </code></pre>
  
  <p>this is my code in question1.xml.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:padding="10dp" &gt;
  
      &lt;ScrollView
          android:id="@+id/scrollView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="452dp"
              android:orientation="vertical" &gt;
  
              &lt;ImageView
                  android:id="@+id/imageView1"
                  android:layout_width="match_parent"
                  android:layout_height="250dp"
                  android:layout_below="@+id/textView2"
                  android:layout_centerHorizontal="true"
                  android:src="@drawable/clay" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="24dp"
                  android:text="YANG MANA SATUKAH DI ANTARA AYAT-AYAT BERIKUT YANG BENAR ?"
                  android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
              &lt;RadioGroup
                  android:id="@+id/radioGroup1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/rb1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_above="@+id/radioButton2"
                      android:text="A.Tanah liat yang leper lebih berat" /&gt;
  
                  &lt;RadioButton
                      android:id="@+id/rb2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_above="@+id/radioButton3"
                      android:text=" B. Kedua-dua tanah liat adalah sama berat" /&gt;
  
                  &lt;RadioButton
                      android:id="@+id/rb3"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_above="@+id/button1"
                      android:layout_alignLeft="@+id/radioButton2"
                      android:layout_marginBottom="14dp"
                      android:text="C.Bola tanah liat lebih berat" /&gt;
              &lt;/RadioGroup&gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="50dp"
                  android:layout_height="50dp"
                  android:layout_gravity="right"
                  android:background="@drawable/nextnext" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>this is my code for the second page that i want the selected radio button value to be displayed. </p>
  
  <p>question2. java</p>
  
  <pre><code>  public class question2 extends Activity
    {
    private Button Button2;
    public RadioButton r1,r2,r3,r4,r5;
    public RadioGroup rg1,rg2;
    public String a2,b2,total;
  
    public TextView output ;
  
  
  
      public void onCreate(Bundle savedInstanceState)
      {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.question2);
  
  
  
     output = (TextView)findViewById(R.id.textView5);
     r1 = (RadioButton)findViewById(R.id.rb1);
  
     r2 = (RadioButton)findViewById(R.id.rb2);
     r3 = (RadioButton)findViewById(R.id.rb3);
  
     r4 = (RadioButton)findViewById(R.id.rb4);
     r5 = (RadioButton)findViewById(R.id.rb5);
     rg1 = (RadioGroup)findViewById(R.id.radioGroup1);     
     rg2 = (RadioGroup)findViewById(R.id.radioGroup2);
  
     Object RadioButton;
     r1= (RadioButton).getValue();
     r2 =(RadioButon).getValue();
     r3 =(RadioButon).getValue();
  
  
  
   //Button2
          Button2 = (Button) findViewById(R.id.button1);
          Button2.setOnClickListener((new OnClickListener()
          {
  
              public void onClick(View view) 
              {
                  Intent intent = new Intent(view.getContext(),question3.class);
  
  
                  startActivityForResult(intent,0);
              }
          }
              ));
  
          {
                  switch(rg2.getCheckedRadioButtonId()){
  
                  case R.id.rb4:
                      if (r4.isChecked()){
                          //a2 =0;
  
                      }
                          break;
  
  
  
                  case R.id.rb5:
                      if (r5.isChecked()){
                          //b2 = 1;
  
  
                      }
                          break;
  
                         //total = rg1.getCheckedRadioButtonId()+rg2.getCheckedRadioButtonId()  ;    
                  }}
          //receive the arguments from the previous Activity
          Bundle extras = getIntent().getExtras();
          if (extras==null) {
              return;
          }
  
          output = (TextView) findViewById(R.id.textView5);
  
          Bundle data = this.getIntent().getExtras();
  
           r1=data.getValue(r1);
           r2=data.getValue(r2);
           r3=data.getValue(r3);
  
           double result = 0;
  
          if (r1 == "")
          {
              result+ = 1;
          }
          else if (r2 == "true"){
              result+ = 0;}
  
          else if (r3=="true")
          {
              result+ = 0;
          }
          else {
              result + =0;
          }
  
          }
          }
  
          }
  </code></pre>
  
  <p>question2.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:padding="10dp" &gt;
  
      &lt;ScrollView
          android:id="@+id/scrollView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="452dp"
              android:orientation="vertical" &gt;
  
              &lt;ImageView
                  android:id="@+id/imageView1"
                  android:layout_width="match_parent"
                  android:layout_height="250dp"
                  android:layout_below="@+id/textView3"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="20dp"
                  android:layout_weight="0.13"
                  android:src="@drawable/soklan2" /&gt;
  
              &lt;RadioGroup
                  android:id="@+id/radioGroup2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignLeft="@+id/textView4"
                  android:layout_below="@+id/textView4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/rb4"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="A. Ya" /&gt;
  
                  &lt;RadioButton
                      android:id="@+id/rb5"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignLeft="@+id/radioGroup1"
                      android:layout_below="@+id/radioGroup1"
                      android:text="B. Tidak" /&gt;
              &lt;/RadioGroup&gt;
  
              &lt;TextView
                  android:id="@+id/textView5"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/radioGroup2"
                  android:layout_marginTop="20dp"
                  android:text="Result"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="50dp"
                  android:layout_height="50dp"
                  android:layout_gravity="right"
                  android:background="@drawable/nextnext" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I would like to know, how to retrieve the value from question 1 and displayed it on question2 page. </p>