How To Store Selected Radiobutton Value In Android?
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
Solution 1:
Example:
let this action be done on your button click
so write this code inside your click listener
if(radioButton1.isSeleceted())
Stringtemp= radioButton1.getText().toString();
if(radioButton2.isSeleceted())
Stringtemp= radioButton2.getText().toString();
then put the temp value in your Database
Solution 2:
No need to use database.
you can save values in Shared preference
.
Ex:
if(radioButton1.isSeleceted()) {
PrefarenceName.putString("gender","1");
} elseif(radioButton2.isSeleceted())
PrefarenceName.putString("gender","0");
}
Stringgendertype= prefarenceName.getString("gender");
if(gendertype == 1) {
radioButton1.setSelcted(true);
} else {
radioButton2.setSelcted(true);
}
Post a Comment for "How To Store Selected Radiobutton Value In Android?"