无线电集团作为循环寻呼指示 [英] Radio Group as Circular Page Indicator
问题描述
我想使用RadioGroup中作为CircularPageIndicator。问题是与RadioGroup.OnCheckedChangeListener。它似乎把它叫做自我时的使用onPageSelected 被调用。不过,我希望它当我选择正在提供其应改变以数组索引的位置景色的单选按钮的工作,反之亦然,即。然而,它好像当我改变支票上的单选按钮,永远不会被调用onCheckedChange所以onCheckedChange从来没有触发。
I am trying to use RadioGroup as a CircularPageIndicator. The problem is with the RadioGroup.OnCheckedChangeListener. It seems to call it self when onPageSelected is called. However I want it to work vice versa i.e. when I select a radioButton it should change a view based on the location of the Array index being provided. However it seems as if onCheckedChange is never called when I change a check on the radio button and so onCheckedChange never triggers.
public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener, OnPageChangeListener {
ViewPager mImagePager;
ImagePagerAdapter mPagerAdapter;
RadioGroup mPageIndicator;
boolean swipeChange = false;
int[] mRadioButtonIds = new int[] { R.id.radio0, R.id.radio1, R.id.radio2, R.id.radio3, R.id.radio4 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initComponents();
mPageIndicator.setOnCheckedChangeListener(this);
mImagePager.setAdapter(mPagerAdapter);
mImagePager.setOnPageChangeListener(this);
}
/**
*
*/
private void initComponents() {
mPageIndicator = (RadioGroup) findViewById(R.id.radioGroup1);
mImagePager = (ViewPager) findViewById(R.id.imgPager);
mPagerAdapter = new ImagePagerAdapter();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int pSelectedPagePosition) {
swipeChange = true;
mPageIndicator.check(mRadioButtonIds[pSelectedPagePosition]);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (!swipeChange) {
int itemPosition = Arrays.asList(mRadioButtonIds).indexOf(checkedId);
mImagePager.setCurrentItem(itemPosition, true);
swipeChange = false;
}
}
}
请注意:我不希望使用任何第三方code / lib中创建一个自定义通知页标志
Note : I don't want to use any third party code/lib to create a custom Circular Page Indicator.
任何一个可以请在这里指出一个错误。有没有理由不RadioGroup中工作?
Can any one please point a mistake here. Is there a reason for the RadioGroup not to work?
推荐答案
我忘了看看文档!
http://developer.android.com/guide/topics/ UI /控制/ radiobutton.html
这篇关于无线电集团作为循环寻呼指示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!