我正在创建一个包含7 个 RadioGroups的活动,每个带有5 个 RadioButtons。我的问题是我只获得了一个 RadioGroup (lvl_mon) 的选定索引,而其他 6 个返回-1,但是它们被选中。我的代码是:
lvl_mon = (RadioGroup)findViewById(R.id.lvl_monday);
lvl_tue = (RadioGroup)findViewById(R.id.lvl_tuesday);
lvl_wed = (RadioGroup)findViewById(R.id.lvl_wednesday);
lvl_thu = (RadioGroup)findViewById(R.id.lvl_thursday);
lvl_fri = (RadioGroup)findViewById(R.id.lvl_friday);
lvl_sat = (RadioGroup)findViewById(R.id.lvl_saturday);
lvl_sun = (RadioGroup)findViewById(R.id.lvl_sunday);
int index_mon = lvl_mon.indexOfChild(findViewById(lvl_mon.getCheckedRadioButtonId()));
int index_tue = lvl_tue.indexOfChild(findViewById(lvl_tue.getCheckedRadioButtonId()));
int index_wed = lvl_wed.indexOfChild(findViewById(lvl_wed.getCheckedRadioButtonId()));
int index_thu = lvl_thu.indexOfChild(findViewById(lvl_thu.getCheckedRadioButtonId()));
int index_fri = lvl_fri.indexOfChild(findViewById(lvl_fri.getCheckedRadioButtonId()));
int index_sat = lvl_sat.indexOfChild(findViewById(lvl_sat.getCheckedRadioButtonId()));
int index_sun = lvl_sun.indexOfChild(findViewById(lvl_sun.getCheckedRadioButtonId()));