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?
Asked
Active
Viewed 2,344 times
2 Answers
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
-
But I want to store value of radiobutton not text.For example, 0 for male and 1 for female.So where I have to set value of radio button? – Digma Chauhan Sep 06 '12 at 07:11
-
there is no male female concept in radio buttons : u can do this... radioButton1.setTag("0"); radioButton2.setTag("1"); and use getTag() in above code instead of getText() – Aditya Nikhade Sep 06 '12 at 07:15
-
@DigmaChauhan DID u find your solution you wanted? – Aditya Nikhade Sep 06 '12 at 07:49
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