Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewPagerIndicator does not refresh

first of all I am using the ViewPagerIndicator from the following link to display the count of views inside of my view-pager: http://viewpagerindicator.com/

I used a CirclePageIndicator with just the usually code... my XML looks like this:

<FrameLayout
    android:id="@+id/detailFragment"
    android:name="detailFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/pageIndicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:fillColor="@android:color/black"
        app:pageColor="@android:color/white"
        app:radius="6dp"
        app:strokeColor="@android:color/darker_gray"
        app:strokeWidth="1dp" />
</FrameLayout>

My java code to set the adapter and the indicator is also nothing special and will be posted below (from my activity class)

  final ViewPager pager = (ViewPager) this.findViewById(R.id.viewpager);
  final DutyViewPager adapter = new DutyViewPager(this.getFragmentManager(), pkid, pager.getAdapter());
  pager.setAdapter(adapter);
  final CirclePageIndicator cIndicator = (CirclePageIndicator) this.findViewById(R.id.pageIndicator);
  cIndicator.setViewPager(pager);

Problem: Lets say, we have a navigation with two elements linked to two different ViewPagerAdapter. The first element links to the adapter A, which displays a count of 2 fragments and the second element links to the adapter B, which displays a count of 3 fragments. After clicking at the first element my view will update with adapter A, loading the first fragment from the adapter and showing 2 circles as adapter-count - so basicly, everything is as expected till now. After clicking at the second element, my view is lodaing the adapter B, but the view is still showing only 2 circles, so I guess the indicator is not updating or something... the problem is fixed at the moment I swipe to the right side to display the next fragment in adapter B. (it shows 3 circles after swiping)

Just wondering if it´s just me or if someone else got this problem (and a solution) as well?

like image 995
user1502353 Avatar asked Dec 08 '25 21:12

user1502353


1 Answers

I had the same problem before, after looking into the onDraw method in CirclePageIndicator.java, I found that it was caused by setting snap to true. After changing snap to false, everything looks good.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="StyledIndicators" parent="Theme.Light">
        <item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
    </style>

    <style name="CustomCirclePageIndicator">
        <item name="snap">false</item>
    </style>
</resources>
like image 54
Kai-jie Ke Avatar answered Dec 10 '25 10:12

Kai-jie Ke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!