get Radio Selected Index - Android User Interface

Android examples for User Interface:RadioButton

Description

get Radio Selected Index

Demo Code

import android.widget.RadioGroup;

public class Main {

  public static int getRadioSelectedIndex(RadioGroup radioGroup) {
    int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
    if (checkedRadioButtonId <= 0) {
      return -1;//w  w  w  . j a  v a  2 s .c o m
    }
    return radioGroup.indexOfChild(radioGroup
        .findViewById(checkedRadioButtonId));
  }
}

Related Tutorials