更新:
可以使用listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);实现
多个RadioButton必须放在同一个RadioGroup中才有单选效果,但是在ListView的item中包含呢?
在Adapter中:
private int mCheckedPosition = -1;//默认不选中任何RadioButton//下面是关键mHolder.couponRBChecked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { //确保只有一项被选中,并且setChecked方法会触发onCheckedChanged的调用,所以只有在b为true,即RadioButton被选中的情况下才更新列表 if(b) { mCheckedPosition = position; notifyDataSetChanged(); } } }); mHolder.couponRBChecked.setChecked(mCheckedPosition == position);