radioButtons = new RadioButton[rgMain.getChildCount()]; //遍历RadioGroup
for (int i = 0; i < radioButtons.length; i++) {
radioButtons[i] = (RadioButton) rgMain.getChildAt(i);
radioButtons[i].setTag(i); //设置tag
radioButtons[i].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b)
//切换ViewPager页面
showFragment((int) compoundButton.getTag()); //获取tag
}
});
}