views:

250

answers:

1

I am trying to perform a rating system, where with the choices to select from returns a constant number so I can insert a value into a database. My intentions are to have 3 choices, 'Great', 'Mediocre' and 'Bad'. I would like Great to be a constant for '3', Mediocre to have a constant '2' and Bad to have a constant for '1'. I would like to insert only the numerical values if possible, any easy way to do this?

Anthony

+3  A: 

The RadioGroup has the method getCheckedRadioButtonId() which returns the resource id of the selected RadioButton.

You could setup a switch case like:

private static final int CHOICE_GREAT = 3;
private static final int CHOICE_MEDIOCRE = 2;
private static final int CHOICE_BAD = 1;

int selected = getRating();

private int getRating() {
    switch (ratingGroup.getCheckedRadioButtonId()) {
       case R.id.RadioButtonGreat:
          return CHOICE_GREAT;
       case R.id.RadioButtonMediocre:
          return CHOICE_MEDIOCRE;
       case R.id.RadioButtonBad:
          return CHOICE_BAD;
    }
}
Tim H