Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Set viewpager's first item

I have a viewpager. This viewpager can have dynamic number of pages depends on server and user can start with any page they want. So I programmed like below..

mViewPager.setAdapter(mAdapter);
mViewPager.setCurrentItem(mStartPosition);

mStartPosition is a position to start..

My question is here. This view pager always load pages where 0, 1 and mStartPosition and nearby pages loaded sequentially. If mStartPosition is 10, then loading 0, 1, and load 9,10,11. It slow down performance and waste data.

I want just start with mStartPosition and nearby page. Help me~!

like image 227
Lee Jeongmin Avatar asked Oct 16 '25 13:10

Lee Jeongmin


1 Answers

setCurrentItem(int item) sets current item with smooth animated transition.

You just need to use mViewPager.setCurrentItem(mStartPosition, false);

Then it will only load 9,10,11

like image 146
Sohaib Avatar answered Oct 19 '25 14:10

Sohaib



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!