Open datacomp opened 11 years ago
quick fix (I would prefer to add a new "addOnPageChangeListener" method for ViewPager)
When you use the setViewPager method, the onPageChangeListener will be set to the called indicator. After the multiple binds with the setViewPager you can overwrite the wrong listener. Here is a snippet based on the "samples" code:
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mTopIndicator = (TitlePageIndicator)findViewById(R.id.titleIndicator);
mTopIndicator.setViewPager(mPager);
// the mPager onPageChangeListener is now set to the mTopIndicator
mCircleIndicator = (CirclePageIndicator)findViewById(R.id.circleIndicator);
mCircleIndicator.setViewPager(mPager);
// the mPager onPageChangeListener is now set to the mCircleIndicator and the previous mTopIndicator listener is overwritten. Only the mCircleIndicator works fine.
// the solution: set the OnPageChangeListener manually and call all your indicators
mPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
mTopIndicator.onPageSelected(arg0);
mCircleIndicator.onPageSelected(arg0);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
mTopIndicator.onPageScrolled(arg0, arg1, arg2);
mCircleIndicator.onPageScrolled(arg0, arg1, arg2);
}
@Override
public void onPageScrollStateChanged(int arg0) {
mTopIndicator.onPageScrollStateChanged(arg0);
mCircleIndicator.onPageScrollStateChanged(arg0);
}
});
I want to use both circlepageindicator and titlepageindicator on same page but at a time only one is working. Please tell me the solution ASAP.