Load data when user stops swiping in fragmentviewpager in android? -


load fragment when user stops swiping instead of previous,current,next pattern in fragmentviewpager in android? load single fragment @ time in fragmentviewpager instead of multiple.

on fragment load fragmentviewpager sets setuservisiblehint true of current fragment. through can put delay in loading fragment in fragmentviewpager. in below code have put delay of 1000 ms.

@override public boolean getuservisiblehint() {

    boolean isvisible = super.getuservisiblehint();     return isvisible; }  public runnable handledelays = new runnable() {     @override     public void run() {         if (getuservisiblehint()) {             // application logic              }     } }; private handler pagerhandler;  @override public void setuservisiblehint(boolean isvisibletouser) {     super.setuservisiblehint(isvisibletouser);     if (this.isvisible()) {         if (!isvisibletouser) {             pagerhandler.removecallbacks(handledelays);         } else {             pagerhandler.removecallbacks(handledelays);             pagerhandler.postdelayed(handledelays, 1000);         }     } else {         if (pagerhandler != null) {             if (!isvisibletouser) {                 pagerhandler.removecallbacks(handledelays);             } else {                 pagerhandler.removecallbacks(handledelays);                 pagerhandler.postdelayed(handledelays, 1000);             }         } else {             pagerhandler = new handler();         }     } } 

Comments