1

I am looking for and example source code for stop pre-loading pages in viewpager. Normally android viewpager loads the next and previous page(s) automatically. My target is to use viewpager and I want to show animation on views(which are present in the pages) when it visible to the user. Basically it is to continue with the previous of post.

If you can give me any working example(complete code) it will be so kind. I found so many but did not find any working implementation. Thanks for your help. Regards Biswajit

Community
  • 1
  • 1
Biswajit Das
  • 644
  • 7
  • 26
  • look at this thread http://stackoverflow.com/questions/10024739/how-to-determine-when-fragment-becomes-visible-in-viewpager?rq=1 – Sabeer Apr 02 '16 at 05:18

1 Answers1

6

Like you already know there is no way of stopping viewpagers from loading . The only way out is to use this method setUserVisibleHint add this to your fragment, and do all the animation you want to in this method

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        // animate here
     Log.e(TAG, "animate here");
    }else{
     Log.e(TAG, "fragment is no longer visible");
       // fragment is no longer visible
    }
}

This will be called only when that particular tab is visible to user.

Biswajit Das
  • 644
  • 7
  • 26
D Agrawal
  • 471
  • 4
  • 15
  • Well perfect. it is loading with pause. – Biswajit Das Apr 02 '16 at 05:59
  • If this did solve your problem ,please accept the answer. – D Agrawal Apr 02 '16 at 06:01
  • Well it solved more than partially. but while loading it is showing "Animate here" and when it is no longer visible. Then **first it is showing "Animate here" and the showing "fragment is no longer visible"**. I have edited your code. Please look for your reference. – Biswajit Das Apr 02 '16 at 06:07
  • I have never come across this problem. Will have to look into. But It is maybe because when you change between tab , at a point, there is some portion of two adjacent tabs that is visible, so maybe thats why. – D Agrawal Apr 02 '16 at 06:21
  • Sure. Thanks. will be waiting for your answers. – Biswajit Das Apr 02 '16 at 06:23