title: Radio buttons in android studio
body: <p>I want to have list of radio buttons and after i select one and click next I would like to perform different actions depending on which button was pressed. i am trying currently to set text for some test TextView and for every radio button it says it is -1.</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.RadioButton;
  import android.*;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  
  public class Polynomials extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          final View polyView = inflater.inflate(R.layout.fragment_poly, container, false);
  
          //layout
          RadioGroup rbg = (RadioGroup) polyView.findViewById(R.id.rBGPoly);
          Button next = (Button) polyView.findViewById(R.id.polyButton);
          final TextView test = (TextView) polyView.findViewById(R.id.jdtTest);
          final RadioButton but1 = (RadioButton) polyView.findViewById(R.id.radioButton1);
          RadioButton but2 = (RadioButton) polyView.findViewById(R.id.radioButton2);
          RadioButton but3 = (RadioButton) polyView.findViewById(R.id.radioButton3);
          RadioButton but4 = (RadioButton) polyView.findViewById(R.id.radioButton4);
          RadioButton but5 = (RadioButton) polyView.findViewById(R.id.radioButton5);
          RadioButton but6 = (RadioButton) polyView.findViewById(R.id.radioButton6);
          RadioButton but7 = (RadioButton) polyView.findViewById(R.id.radioButton7);
  
  
  
  
  
  
          RadioGroup g = (RadioGroup)polyView.findViewById(R.id.rBGPoly);
  
  
          final int selected = g.getCheckedRadioButtonId();
  
  
  
          next.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
  
  test.setText(""+selected);
  
              }
          });
  
  
  
  
  
  
  
  
  
  
          return polyView;
      }
  
  
  
  }
  </code></pre>
  
  <p>and this is my 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:id="@+id/jdttae"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
  
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/jdtchoose"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="31dp"
          android:text="How many terms?"
          android:textSize="18sp" /&gt;
  
      &lt;RadioGroup android:id="@+id/rBGPoly"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;RadioButton
              android:id="@+id/radioButton1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="90dp"
              android:layout_marginLeft="180dp"
              android:text="1"
              android:layout_below="@+id/jdtchoose"
              android:layout_alignLeft="@+id/jdtchoose"
  
             /&gt;/&gt;
  
          &lt;RadioButton
              android:id="@+id/radioButton2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="2"
              android:layout_marginLeft="180dp"
              android:layout_marginTop="31dp"
              android:layout_below="@+id/radioButton1"
              android:layout_alignLeft="@+id/radioButton1"
             /&gt;/&gt;
  
          &lt;RadioButton
              android:id="@+id/radioButton3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="3"
              android:layout_marginLeft="180dp"
              android:layout_marginTop="31dp"
              android:layout_below="@+id/radioButton2"
              android:layout_alignLeft="@+id/radioButton2"
              /&gt;/&gt;
  
          &lt;RadioButton
              android:id="@+id/radioButton4"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="31dp"
              android:layout_marginLeft="180dp"
              android:text="4"
              android:layout_below="@+id/radioButton3"
              android:layout_alignLeft="@+id/radioButton3"
              /&gt;/&gt;
  
  
          &lt;RadioButton
          android:id="@+id/radioButton5"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="31dp"
              android:layout_marginLeft="180dp"
          android:text="5"
          android:layout_below="@+id/radioButton4"
          android:layout_alignLeft="@+id/radioButton4"
          /&gt;/&gt;
  
  
  
  
  
  
  
      &lt;RadioButton
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="6"
          android:layout_marginLeft="180dp"
          android:id="@+id/radioButton6"
          android:layout_below="@+id/radioButton5"
          android:layout_alignLeft="@+id/radioButton5"
          android:layout_marginTop="31dp"
          /&gt;/&gt;
  
      &lt;RadioButton
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="7"
          android:layout_marginLeft="180dp"
          android:id="@+id/radioButton7"
          android:layout_below="@+id/radioButton6"
          android:layout_alignParentBottom="false"
          android:layout_alignLeft="@+id/radioButton6"
          android:layout_marginTop="31dp"
          android:checked="false"
          /&gt;/&gt;
  
     &lt;/RadioGroup&gt;
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Next"
          android:id="@+id/polyButton"
          android:layout_alignParentBottom="true"
          android:layout_alignLeft="@+id/jdtchoose"
          android:layout_marginBottom="26dp"
          android:layout_alignRight="@+id/jdtchoose" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Test"
          android:id="@+id/jdtTest"
          android:editable="false"
          android:textSize="18sp"
          android:layout_alignBaseline="@+id/polyButton"
          android:layout_alignBottom="@+id/polyButton"
          android:layout_toLeftOf="@+id/polyButton"
          android:layout_marginRight="47dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>