setTag,getTage复用

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
}
});
}
posted @ 2018-01-21 16:55  dub  阅读(107)  评论(0编辑  收藏  举报