android - onloadmore method loads only 5 items on resume -
the app should load 5 items each time user scrolls way down, works fine when user change activity , return brows activity (the main activity) loads 5 items
here my code scrolling
recyclerview.setonscrolllistener(new endlessrecycleronscrolllistener( layoutmanager) { @override public void onloadmore(int current_page) { int limit = current_page * 5; loadmoreitems(limit); } }); return rootview; }
load more items method
private void loadmoreitems(int limit) { parsequery<parseobject> query = parsequery.getquery("product"); query.setlimit(limit).orderbydescending("createdat"); dialog = new progressdialog(getactivity()); dialog.settitle("loading"); dialog.setmessage("please wait..."); dialog.show(); query.findinbackground(new findcallback<parseobject>() { public void done(list<parseobject> scorelist, parseexception e) { dialog.dismiss(); if (e == null) { data.clear(); (int = 0; < scorelist.size(); a++) { parseobject object = scorelist.get(a); itemsmodel model = new itemsmodel(); model.setdate(string.valueof(object.getcreatedat() .tolocalestring())); model.setprice(object.getnumber("price").tostring() + " r.o"); model.settitle(object.getstring("title")); model.setphone(object.getnumber("phone").tostring()); model.setdesc(object.getstring("desc")); model.setimagefile(object.getparsefile("image") .geturl()); model.setobjectid(object.getobjectid()); data.add(model); } adapter.updatedata(data); } else if (e.getcode() == parseexception.connection_failed) { toast.maketext(getactivity(), "no internet connection please check connection!", toast.length_long).show(); } else { toast.maketext(getactivity(),"error:"+e.getmessage(), toast.length_long).show(); } } }); }
load data method
private void loaddata() { parsequery<parseobject> query = parsequery.getquery("product"); query.setlimit(5).orderbydescending("createdat"); dialog = new progressdialog(getactivity()); dialog.settitle("loading"); dialog.setmessage("please wait..."); dialog.show(); query.findinbackground(new findcallback<parseobject>() { public void done(list<parseobject> scorelist, parseexception e) { dialog.dismiss(); if (e == null) { data.clear(); (int = 0; < scorelist.size(); a++) { parseobject object = scorelist.get(a); itemsmodel model = new itemsmodel(); model.setdate(string.valueof(object.getcreatedat() .tolocalestring())); model.setprice(object.getnumber("price").tostring() + " r.o"); model.settitle(object.getstring("title")); model.setphone(object.getnumber("phone").tostring()); model.setdesc(object.getstring("desc")); model.setimagefile(object.getparsefile("image") .geturl()); model.setobjectid(object.getobjectid()); data.add(model); } adapter = new recycleviewadapter(data, getactivity()); adapter.setclicklistner(browsefragment.this); recyclerview.setadapter(adapter); } else if (e.getcode() == parseexception.connection_failed) { toast.maketext(getactivity(), "no internet connection please check connection!", toast.length_long).show(); } else { toast.maketext(getactivity(),"error:"+e.getmessage(), toast.length_long).show(); } } }); }
this how call load data inside onresume
public void onresume() { super.onresume(); loaddata(); }
Comments
Post a Comment