StaggeredView android endless scroll issue -
i' m trying implement infinite scrolling staggered view. when started used linearlayoutmanager
, https://gist.github.com/ssinss/e06f12ef66c51252563e infinite scrolling. changed staggeredgridlayoutmanager
, haven t found way implement endless scrolling. i've tried far:
mrecyclerview = (recyclerview) rootview.findviewbyid(r.id.recycler_view); //mrecyclerview.additemdecoration(new horizontaldivideritemdecoration.builder(getactivity()).color(color.black).build()); final staggeredgridlayoutmanager staggeredgridlayoutmanager = new staggeredgridlayoutmanager(2,staggeredgridlayoutmanager.vertical); mrecyclerview.setlayoutmanager(staggeredgridlayoutmanager); updatelist("aww"); mrecyclerview.addonscrolllistener(new recyclerview.onscrolllistener() { @override public void onscrolled(recyclerview recyclerview, int dx, int dy) { visibleitemcount = staggeredgridlayoutmanager.getchildcount(); totalitemcount = staggeredgridlayoutmanager.getitemcount(); int[] firstvisibleitems = null; firstvisibleitems = staggeredgridlayoutmanager.findfirstvisibleitempositions(firstvisibleitems); if (firstvisibleitems != null && firstvisibleitems.length > 0) { pastvisibleitems = firstvisibleitems[0]; } if (loading) { if ((visibleitemcount + pastvisibleitems) >= totalitemcount) { loading = false; log.d("tag", "load next item"); loadmore("aww"); } } } });
the loadmore function called, items not added screen.
loadmore :
public void loadmore(string subreddit) { counter = counter + 25; count = string.valueof(counter); subreddit = jsonsubreddit; log.d(tag, after_id); subreddit = subredditurl + subreddit + jsonend + "?after" + after_id + "=" + qcount + count + after + "=" + after_id; log.d(tag, subreddit); adapter = new myrecycleradapter(getactivity(), listitemslist); mrecyclerview.setadapter(adapter); requestqueue queue = volley.newrequestqueue(getactivity()); showpd(); jsonobjectrequest jsonobjectrequest = new jsonobjectrequest(request.method.get, subreddit, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d(tag, response.tostring()); hidepd(); try { jsonobject data = response.getjsonobject("data"); after_id = data.getstring("after"); jsonarray children = data.getjsonarray("children"); (int = 0; < children.length(); i++) { jsonobject post = children.getjsonobject(i).getjsonobject("data"); listitems item = new listitems(); item.settitle(post.getstring("title")); item.setthumbnail(post.getstring("thumbnail")); item.seturl(post.getstring("url")); item.setsubreddit(post.getstring("subreddit")); item.setauthor(post.getstring("author")); jsonsubreddit = post.getstring("subreddit"); listitemslist.add(item); } } catch (jsonexception e) { e.printstacktrace(); } adapter.notifydatasetchanged(); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error" + error.getmessage()); hidepd(); } }); queue.add(jsonobjectrequest); }
the problem loadmore()
function executed start program. starting value of visibleitemcount = totalitemcount.
Comments
Post a Comment