Android recyclerview endless scroll listner onScrolled() getting called twice -


this how setting recyclerview.

mrecyclerviewrides = (recyclerview) findviewbyid(r.id.recyclerviewrides);     // use setting improve performance if know changes     // in content not change layout size of recyclerview     mrecyclerviewrides.sethasfixedsize(true);     // use linear layout manager     mlinearlayoutmanager = new linearlayoutmanager(getapplicationcontext());     mrecyclerviewrides.setlayoutmanager(mlinearlayoutmanager);     mridelistadapter = new findridelistadapter(getapplicationcontext(), mrecyclerviewrides, mridedetailarraylist, mimageoptions, mimageloader, this); mrecyclerviewrides.setadapter(mridelistadapter); mrecyclerviewrides.addonscrolllistener(new endlessrecycleronscrolllistener(mlinearlayoutmanager) {         @override         public void onloadmore(int current_page) {             log.e(tag,"scroll count ==> "+(++mintscrollcount));             if(!flagfirstload) {                 moffset = moffset + mlimit;                 getridelist(moffset, mlimit);             }         }     }); 

this code endless recycler view scroll listner.

public abstract class endlessrecycleronscrolllistener extends recyclerview.onscrolllistener { public static string tag = endlessrecycleronscrolllistener.class.getsimplename();  private int previoustotal = 0; // total number of items in dataset after last load private boolean loading = true; // true if still waiting last set of data load. private int visiblethreshold = 1; // minimum amount of items have below current scroll position before loading more. int firstvisibleitem, visibleitemcount, totalitemcount;  private int current_page = 1;  private linearlayoutmanager mlinearlayoutmanager;  public endlessrecycleronscrolllistener(linearlayoutmanager linearlayoutmanager) {     this.mlinearlayoutmanager = linearlayoutmanager; }  /**  * function reset values of properties of class initial  */ public void resetvalues(){     previoustotal = 0;     loading = true;     visiblethreshold = 1;     firstvisibleitem = 0;     visibleitemcount = 0;     totalitemcount = 0; }  @override public void onscrolled(recyclerview recyclerview, int dx, int dy) {     super.onscrolled(recyclerview, dx, dy);      visibleitemcount = recyclerview.getchildcount();     totalitemcount = mlinearlayoutmanager.getitemcount();     firstvisibleitem = mlinearlayoutmanager.findfirstvisibleitemposition();      if (loading) {         if (totalitemcount > previoustotal) {             loading = false;             previoustotal = totalitemcount;         }     }     if (!loading && (totalitemcount - visibleitemcount)             <= (firstvisibleitem + visiblethreshold)) {         // end has been reached          //         current_page++;          onloadmore(current_page);          loading = true;     } }  public abstract void onloadmore(int current_page);} 

so whenever scroll bottom of list onloadmore() gets called twice , intialy when call getridelist() first time onscroll getting invoked. don't understand why?

updated support library , working fine now.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -