0

I have created 2 radio buttons for Gender(Male&Female).I want to store selected radio button value in MySQL. I am connecting Android to MySQL using PHP. In MySQL, I have taken datatype for Gender is tinyint.In PHP script I have written insert query.I want that if male is selected then 0 should be store and female is selected then 1 should be store in MySQL. For that what should I do?

Digma Chauhan
  • 185
  • 1
  • 4
  • 15

2 Answers2

4

Example:

let this action be done on your button click

so write this code inside your click listener

if(radioButton1.isSeleceted())
    String temp = radioButton1.getText().toString();
if(radioButton2.isSeleceted())
    String temp = radioButton2.getText().toString();

then put the temp value in your Database

Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
Aditya Nikhade
  • 1,373
  • 10
  • 15
1

No need to use database. you can save values in Shared preference .

Ex:

 if(radioButton1.isSeleceted()) {
     PrefarenceName.putString("gender","1");

 } else if(radioButton2.isSeleceted())
     PrefarenceName.putString("gender","0");
 } 

  String gendertype = prefarenceName.getString("gender");

  if(gendertype == 1) {
      radioButton1.setSelcted(true);

  } else {
      radioButton2.setSelcted(true);
  }
Daud Arfin
  • 2,499
  • 1
  • 18
  • 37
gkondati
  • 516
  • 4
  • 16