I'm implementing SQLite
Database in Android. I'm stuck at this point that how to store RadioButton's value in that database. I'm using RadioGroup
. Please help me I'm a Beginner in Android Development.
Asked
Active
Viewed 7,280 times
0

Shree Krishna
- 8,474
- 6
- 40
- 68

Dhaval Mistry
- 476
- 1
- 9
- 17
-
1Please post the code that you tried. – Prerak Sola Apr 09 '16 at 14:04
1 Answers
1
Let's say you have myRadioGroup
as RadioGroup,
Now at first you have to get the id
of the selected RadioButton like here
int id = myRadioGroup.getCheckedRadioButtonId();
Then after have to find the RadioButton by the id you got like
mySelectedRadioButton = (RadioButton) findViewById(id);
Then get the text of it and save to sqlite
String mySelectedText = mySelectedRadioButton.getText().toString();
//Save the value to database

Shree Krishna
- 8,474
- 6
- 40
- 68
-
Wouldn't it be better to store an integer variable, which is modified by a RadioButton click? and then retrieve this "positional id" and use to re-check the RadioButton on the Activity reload? – Phantômaxx Apr 09 '16 at 14:11
-
1@BobMalooga Yes that would be much better, I thought S(he) is in confuse on getting the text so that I simply explained about it. He will definitely apply your idea when S(he) feels it's needed. I really appreciate your suggestions. – Shree Krishna Apr 09 '16 at 14:17
-
thank you sir. i got what you are saying but still confused with this.i want to perform gender operation. int id=r1.getCheckedRadioButtonId(); if(id == 0) { String radioButtonText = rmale.getText().toString(); } else { String radioButtonText = rfemale.getText().toString(); } i did this now what should i do? – Dhaval Mistry Apr 09 '16 at 14:55
-
@DhavalMistry have a look [here](http://stackoverflow.com/questions/18179124/android-getting-value-from-selected-radiobutton). – Shree Krishna Apr 09 '16 at 14:58