Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when calling setCurrentItem to newly added view to adapter. #18

Open
alichherawalla opened this issue Aug 8, 2016 · 3 comments

Comments

@alichherawalla
Copy link

Hi,
Thank you so much for this wonderful library. It is very useful and has helped me immensely.

But I found an issue with using setCurrentItem on my viewPager.
Here is the flow :

I have initialized the ViewPager, PagerAdapter and InkPageIndicator
testAdapter = new SimplePagerAdapter(testList);
testPager.setAdapter(testAdapter);
testIndicator.setViewPager(testPager);

Then I add few views to testList and call notifyDataSetChanged on testAdapter.
(Which internally calls setPageCount and pageCount gets initialized correctly, which internally calls requestLayout , which would be called on next idle cycle)
testList.add(newView);
testPager.getAdapter().notifyDataSetChanged();

Then I immediately call setCurrentItem(newViewIndex, false);
which calls setPageSelected inline which calls setSelectedPage. setSelectedPage tries to call
createMoveSelectedAnimator but dotCenterX doesn't contain newly added view's dot's X value. This is because calculateDotPositions isn't called as yet since onMeasure is not called as yet and is waiting to be called in idle cycle.

Could you please give me a suggestion on how can I fix this. I would create the patch and create pull request for the same.

@siyamed
Copy link

siyamed commented Sep 12, 2016

this happens for a fragment restore too.

@leonardo2204
Copy link

Could you guys provide a sample with the problem ?
I think it's easy to fix the problem that way

@AbdullahProgrammer426351

Try viewpager.setCurrentItem() in thread because this helped for me:

Thread td = new Thread() {
@OverRide
public void run() {
super.run();
try {
sleep(500);
} catch (Exception e) {
e.printStackTrace();
} finally {
viewPager.setCurrentItem(indexNo);
}
}

    };td.start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants