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