ongakuer / CircleIndicator

A lightweight indicator like in nexus 5 launcher
Apache License 2.0
4.27k stars 712 forks source link

Not updated with viewpager runtime. #33

Closed shailesh242121 closed 8 years ago

shailesh242121 commented 9 years ago

If I have setup a view pager and added this lib. then if runtime there is one page added or one item is deleted. this doesn't update.

What i have done is when my pager is updated. I have call the method

createIndicators(View Pager);

this create a new list of pagerindicator it is OK. but the value/progress doesn't remain.

for this i have to call method setProgress(viewpager.getCurrentIndex());

This will move the the currenct page indicator to the right position.but in this situation there are two current page indicator on the screen first is on index one. and other one is on the right positoin.

There is need to add a observer with adapter or viewpager with this library.

hope you understand the issue.

shailesh242121 commented 9 years ago

Done with simple tric

If Any one want to use this

indicator.setViewPager(viewPager); indicator.onPageSelected(viewPager.getCurrentItem());

public void createIndicators(ViewPager viewPager,int selectedPosition) { removeAllViews(); if (viewPager.getAdapter() == null) { return; } int count = viewPager.getAdapter().getCount(); if (count <= 0) { return; }

    for (int i = 0; i < count; i++) {
        if(i==0 && selectedPosition==-1)
            addIndicator(mIndicatorBackgroundResId, mAnimationOut);
        else {
            if(i==selectedPosition)
                addIndicator(mIndicatorBackgroundResId, mAnimationOut);
                else
            addIndicator(mIndicatorUnselectedBackgroundResId, mAnimationIn);
        }
    }
}
ongakuer commented 9 years ago

You can view https://github.com/ongakuer/CircleIndicator/pull/28 pull request

ongakuer commented 8 years ago

Fix https://github.com/ongakuer/CircleIndicator/commit/f83dfa4f9d33d8725ea0ae6fa9457f99ca4deafb