1
嗨,大家好,我有一个4值,即4个单选按钮,我想检查他们是否被检查或不会如何做?我曾经尝试这样做如何检查在android中选中哪个单选按钮?
public void onRadioButtonClicked(View v){
// Your code on click
radioTypeGroup = (RadioGroup) findViewById(R.id.radioType);
radioTypeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int selectedId = radioTypeGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton r1 = (RadioButton) findViewById(R.id.radio_food);
RadioButton r2 = (RadioButton) findViewById(R.id.radio_fitness);
RadioButton r3 = (RadioButton) findViewById(R.id.radio_entertainment);
RadioButton r4 = (RadioButton) findViewById(R.id.radio_events);
if (r1.isChecked()) {
String food = "food";
type = food;
}
if (r2.isChecked()) {
String fitness = "fitness";
type = fitness;
}
但其没有工作,我分配到另一种字符串的方法
这是什么做的是什么呢? – zed
它读取RadioGroup –
中检查的RadioButton的索引,它没有工作:/ – zed