Cómo obtener el valor de RadioButton en RadioGroup
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.myRadioGroup);
2. RadioButton radioButton = (RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
3. Obtener el valor del botón de opción seleccionado:
4. OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkId) {
//Se utiliza en esta función para cambiar el valor del botón de radio seleccionado y // cualquier operación relacionada con su valor, consulte a continuación
selectRadioBtn();
}
})
5 Debe inicializar los cuatro datos anteriores en onCreat;
6. Uso general de Sample:
Contenido en el archivo de diseño xml:
lt; RadioGroup
android: id="@ id/sex_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"gt; p>
RadioButton
android:id="@id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content "
android: check="true"
android: text="male"/gt;
lt;RadioButton
android :id="@ id/mujer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android :text="Mujer "/gt;
lt;/RadioGroupgt;
Implementación de código: id.sex_group);
mMale = (RadioButton) findViewById(R.id.male );
mFemale = (RadioButton) findViewById(R.id.female);
mSex_group.setOnCheckChanged()setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
vacío público en Che
ckedChanged(grupo RadioGroup, int checkId) {
if (mMale.getId() == checkId) {
sexName = mMale.getText().toString();
} else if (mFemale.getId() == checkId) {
sexName = mFemale.getText().toString();
}
}
}
});