android - How to add list of new items to recycler view for exisitng list without moving to top of list -
i trying implement pagination application , partially successful. when call server 6 items , adding items recyclerview. when user comes , scrolls @ last item making call server , fetching page 2 items , adding new items existing list.
here able add new items successfully. problem calling adapter.notifydatasetchanged()
, hence goes first item after adding new items.
how can stop going top of list, should call other adapter.notifydatasetchanged()
? below code of setting adapter
toadlineadapter = new toadlineadapter(mcontext, getdata()); recyclerview.setadapter(toadlineadapter); toadlineadapter.notifydatasetchanged(); toadlineadapter.setclicklistener(this); recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity()));
no need notify when initializing adapter:
toadlineadapter = new toadlineadapter(mcontext, getdata()); recyclerview.setadapter(toadlineadapter); // remove below line // toadlineadapter.notifydatasetchanged(); toadlineadapter.setclicklistener(this); recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity()));
and notify when adding items, ex:
yourlist.add(yourobject); toadlineadapter.notifydatasetchanged();
Comments
Post a Comment