title: Radio buttons keep sending wrong values
body: <p>I'm new to Android and I recently had a homework: one of the activities will send values from radio buttons and some text views to the database, but when I try to run it and check my database, it keeps showing wrong values. The only radio button sending the right value is the first one.</p>
  
  <p>This is the activity:</p>
  
  <pre><code>@SuppressLint("NewApi")
  public class Test extends Activity {
  
      ProgressDialog pDialog;
      TextView idm, nama_mk, kls, mhw_mk;
      Button submit;
      String P1 = "1";
      String P2 = "1";
      String P3 = "1";
      String P4 = "1";
      String P5 = "1";
      RadioGroup cho1;
      RadioGroup cho2;
      RadioGroup cho3;
      RadioGroup cho4;
      RadioGroup cho5;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.test);
  
              if (android.os.Build.VERSION.SDK_INT &gt; 9) {
                  StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                  StrictMode.setThreadPolicy(policy);
              }
  
              cho1 = (RadioGroup) findViewById(R.id.choice1);
              cho1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
                      // TODO Auto-generated method stub
  
                      switch (checkedId) {
                      case R.id.A1:
                          P1 = "1";
                          break;
                      case R.id.B1:
                          P1 = "2";
                          break;
                      case R.id.C1:
                          P1 = "3";
                          break;
                      case R.id.D1:
                          P1 = "4";
                          break;
                      }
                  }
              });
  
              cho2 = (RadioGroup) findViewById(R.id.choice2);
              cho2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
                      // TODO Auto-generated method stub
  
                      switch (checkedId) {
                      case R.id.A2:
                          P2 = "1";
                          break;
                      case R.id.B2:
                          P2 = "2";
                          break;
                      case R.id.C2:
                          P2 = "3";
                          break;
                      case R.id.D2:
                          P2 = "4";
                          break;
                      }
                  }
              });
  
              cho3 = (RadioGroup) findViewById(R.id.choice3);
              cho3.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
                      // TODO Auto-generated method stub
  
                      switch (checkedId) {
                      case R.id.A3:
                          P3 = "1";
                          break;
                      case R.id.B3:
                          P3 = "2";
                          break;
                      case R.id.C3:
                          P3 = "3";
                          break;
                      case R.id.D3:
                          P3 = "4";
                          break;
                      }
                  }
              });
  
              cho4 = (RadioGroup) findViewById(R.id.choice4);
              cho4.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
                      // TODO Auto-generated method stub
  
                      switch (checkedId) {
                      case R.id.A4:
                          P2 = "1";
                          break;
                      case R.id.B4:
                          P2 = "2";
                          break;
                      case R.id.C4:
                          P2 = "3";
                          break;
                      case R.id.D4:
                          P2 = "4";
                          break;
                      }
                  }
              });
  
              cho5 = (RadioGroup) findViewById(R.id.choice5);
              cho5.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                  public void onCheckedChanged(RadioGroup group, int checkedId) {
                      // TODO Auto-generated method stub
  
                      switch (checkedId) {
                      case R.id.A5:
                          P3 = "1";
                          break;
                      case R.id.B5:
                          P3 = "2";
                          break;
                      case R.id.C5:
                          P3 = "3";
                          break;
                      case R.id.D5:
                          P3 = "4";
                          break;
                      }
                  }
              });
  
  
              idm = (TextView) findViewById(R.id.nim_mhs);
              nama_mk = (TextView) findViewById(R.id.nama_mk);
              kls = (TextView) findViewById(R.id.kelas);
              mhw_mk = (TextView) findViewById(R.id.id_mhw_mk);
              submit = (Button) findViewById(R.id.submit);
              submit.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
  
                          new EntryData().execute();
                  }
              });
          }
  
          public class EntryData extends AsyncTask&lt;String, String, String&gt; {
  
              String success;
  
              String url_link = "http://wwwww/xxxxx/yyyyy/zzzzz.php";
  
              @Override
              protected String doInBackground(String... params) {
  
                  String strnama = nama_mk.getText().toString();
                  String stremail = idm.getText().toString();
                  String strpassword = kls.getText().toString();
                  String strmhwmk = mhw_mk.getText().toString();
  
                  List&lt;NameValuePair&gt; nvp = new ArrayList&lt;NameValuePair&gt;();
                  nvp.add(new BasicNameValuePair("matakuliah", strnama));
                  nvp.add(new BasicNameValuePair("idmahasiswa", stremail));
                  nvp.add(new BasicNameValuePair("kelas", strpassword));
                  nvp.add(new BasicNameValuePair("id_mhw_mk", strmhwmk));
                  nvp.add(new BasicNameValuePair("p1", P1));
                  nvp.add(new BasicNameValuePair("p2", P2));
                  nvp.add(new BasicNameValuePair("p3", P3));
                  nvp.add(new BasicNameValuePair("p4", P4));
                  nvp.add(new BasicNameValuePair("p5", P5));
  
                  JSONParser jParser = new JSONParser();
  
                  JSONObject json = jParser.makeHttpRequest(url_link, "POST", nvp);
                  try {
                      success = json.getString("success");
                      if (success == "1") {
  
                          Intent forum = new Intent(getApplicationContext(), ForumActivity.class);                    
                          forum.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          startActivity(forum);                   
                          finish();
                      }
  
  
                  } catch (Exception e) {
                      Toast.makeText(getApplicationContext(), "Error",
                              Toast.LENGTH_LONG).show();
                  }
  
                  return null;
              }
  
          }
  
          public String getJSONUrl(String url) {
              StringBuilder str = new StringBuilder();
              HttpClient client = new DefaultHttpClient();
              HttpGet httpGet = new HttpGet(url);
                  try {
                      HttpResponse response = client.execute(httpGet);
                      StatusLine statusLine = response.getStatusLine();
                      int statusCode = statusLine.getStatusCode();
                      if (statusCode == 200) { // Download OK
                          HttpEntity entity = response.getEntity();
                          InputStream content = entity.getContent();
                          BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                          String line;
                      while ((line = reader.readLine()) != null) {
                          str.append(line);
                      }
                      } else {
                          Log.e("Log", "Failed to download result..");
                      }
                  } catch (ClientProtocolException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
                  return str.toString();
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // getMenuInflater().inflate(R.menu.activity_main, menu);
              return true;
          }
  
      }
  </code></pre>
  
  <p>The PHP code:</p>
  
  <pre><code>&lt;?php
  
  $id_mhs=$_POST['idmahasiswa'];
  $nama_mk = $_POST['matakuliah'];
  $kelas=$_POST['kelas'];
  $id_mhw_mk=$_POST['id_mhw_mk'];
  $pert1=$_POST['p1'];
  $pert2=$_POST['p2'];
  $pert3=$_POST['p3'];
  $pert4=$_POST['p4'];
  $pert5=$_POST['p5'];
  $periode=date('Y-m-d H:i:s');
  include "koneksi.php";
  
  
  $query = "INSERT INTO main_hasil_raw (idmahasiswa,matakuliah,kelas,id_mhw_mk,periode,p1,p2,p3,p4,p5)VALUES('$id_mhs','$nama_mk','$kelas','$id_mhw_mk','$periode','$pert1','$pert2','$pert3','$pert4','$pert5')";
  $hasil = mysql_query($query);
  if($hasil)
      {
      $response["success"] = "1";
          $response["message"] = "Data sukses diinput";
          echo json_encode($response);
      }
      else
      {$response["success"] = "0";
       $response["message"] = "Maaf , terjadi kesalahan";
  
          // echoing JSON response
          echo json_encode($response);
      }
  ?&gt;
  </code></pre>
  
  <p>And the layout (if needed):</p>
  
  <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:scrollbars="vertical" &gt;
  
      &lt;TableLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:shrinkColumns="*"
          android:stretchColumns="*" &gt;
  
      &lt;TextView
          android:id="@+id/nim_mhs"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:text="TextView"
          android:visibility="invisible" /&gt;
  
      &lt;TextView
          android:id="@+id/kelas"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:text="Kelas" /&gt;
  
      &lt;TextView
          android:id="@+id/nama_mk"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:paddingBottom="5dip"
          android:paddingTop="5dip"
          android:text="Nama Matakuliah"
          android:textColor="#333333"
          android:textSize="15sp"
          android:textStyle="bold" /&gt;
  
      &lt;View
          android:layout_height="1dip"
          android:background="#CCCCCC" /&gt;
  
           &lt;TableRow
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal" &gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_span="4"
                  android:padding="10dip"
                  android:text="1.Question One"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow1"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;RadioGroup
                  android:id="@+id/choice1"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="0.4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/A1"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="1"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/B1"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="2"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/C1"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="3"/&gt;
                  &lt;RadioButton
                      android:id="@+id/D1"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="4" /&gt;
              &lt;/RadioGroup&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal" &gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_span="4"
                  android:padding="10dip"
                  android:text="2. Question Two"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow2"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;RadioGroup
                  android:id="@+id/choice2"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="0.4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/A2"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="1"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/B2"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="2"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/C2"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="3"/&gt;
                  &lt;RadioButton
                      android:id="@+id/D2"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="4"/&gt;
              &lt;/RadioGroup&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal" &gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_span="4"
                  android:padding="10dip"
                  android:text="3. Question Three"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow3"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;RadioGroup
                  android:id="@+id/choice3"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="0.4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/A3"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="1"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/B3"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="2"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/C3"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="3"/&gt;
                  &lt;RadioButton
                      android:id="@+id/D3"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="4"/&gt;
              &lt;/RadioGroup&gt;
          &lt;/TableRow&gt; 
  
          &lt;TableRow
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal" &gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_span="4"
                  android:padding="10dip"
                  android:text="4. Question Four"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow4"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;RadioGroup
                  android:id="@+id/choice4"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="0.4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/A4"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="1"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/B4"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="2"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/C4"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="3"/&gt;
                  &lt;RadioButton
                      android:id="@+id/D4"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="4"/&gt;
              &lt;/RadioGroup&gt;
          &lt;/TableRow&gt; 
  
          &lt;TableRow
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal" &gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_span="4"
                  android:padding="10dip"
                  android:text="5. Question Five"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow5"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;RadioGroup
                  android:id="@+id/choice5"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="0.4" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/A5"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="1"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/B5"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="2"/&gt;
  
                  &lt;RadioButton
                      android:id="@+id/C5"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="3"/&gt;
                  &lt;RadioButton
                      android:id="@+id/D5"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="4"/&gt;
              &lt;/RadioGroup&gt;
          &lt;/TableRow&gt; 
  
      &lt;View
          android:layout_height="1dip"
          android:background="#CCCCCC" /&gt;
  
      &lt;Button
          android:id="@+id/submit"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Submit" /&gt;
  
      &lt;TextView
          android:id="@+id/id_mhw_mk"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:text="TextView" /&gt;
  
      &lt;/TableLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Can you help/teach me to solve this problem?</p>