I am creating an Activity that uses ViewPager to show a set of fragments as a slideshow. To indicate which page to show I am using : https://github.com/ongakuer/CircleIndicator
This is the XML for the activity :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/introduction_view_pager"
android:layout_weight="8"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
<me.relex.circleindicator.CircleIndicator
android:id="@+id/circle_indicator"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"/>
<Button
android:layout_weight="1"
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/skip_to_login"
android:onClick="skipToLogin"/>
</LinearLayout>
This is the .java file for the activity :
public class IntroductionActivity extends FragmentActivity {
static final int NO_OF_SLIDES = 4;
ViewPager mViewPager;
private PagerAdapter mPagerAdapter;
Button mButton;
CircleIndicator mCircleIndicator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_introduction);
mButton = (Button)findViewById(R.id.login);
mCircleIndicator = (CircleIndicator)findViewById(R.id.circle_indicator);
mViewPager = (ViewPager)findViewById(R.id.introduction_view_pager);
mPagerAdapter = new SlideScreenPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
mCircleIndicator.setViewPager(mViewPager);
mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
}
@Override
public void onBackPressed() {
if (mViewPager.getCurrentItem() == 0) {
super.onBackPressed();
} else {
mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
}
}
public class SlideScreenPagerAdapter extends FragmentPagerAdapter {
public SlideScreenPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0 : return new IntroductionViewPagerFragmentOne();
case 1 : return new IntroductionViewPagerFragmentTwo();
case 2 : return new IntroductionViewPagerFragmentThree();
case 3 : return new IntroductionViewPagerFragmentFour();
}
return null;
}
@Override
public int getCount() {
return NO_OF_SLIDES;
}
}
}
The fragments work perfectly, but the CircleIndicator does not show. How do i get the CircleIndicator?