android - Loadmore ListView Or RecyclerView -
i'm doing loadmore listview. when scrolled last item, event done loadmore. runs fine except 1 problem, complete data loadmore additional adapter can still recognize new adapter made scratch when see listview reloads rather appended listview earlier. class:
public class storylistmenu extends activity{ private string url; listview listviewstory; private storylistmenuadapter adapter; private list<storymenu> liststory; private progressbar progressbar; private view progressloadmore; private boolean loadmorestatus; private boolean enableloadmore; private int page; private int currentitem; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.layout_story_list_menu); page = 0; loadmorestatus = true; enableloadmore = true; currentitem = 0; progressbar = (progressbar) findviewbyid(r.id.progress_story_list_menu); progressbar.setvisibility(view.visible); progressloadmore = ((layoutinflater) this.getsystemservice(context.layout_inflater_service)).inflate(r.layout.progress_row, null, false); url = getintent().getstringextra("url"); listviewstory = (listview) findviewbyid(r.id.listview_story_list_menu); listviewstory.setdivider(null); liststory = new arraylist<storymenu>(); listviewstory.setonscrolllistener(new onscrolllistener() { @override public void onscrollstatechanged(abslistview view, int scrollstate) {} @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { if(loadmorestatus && totalitemcount > 0 && firstvisibleitem + visibleitemcount == totalitemcount) { loadmorestatus = false; page += appconfig.pagesize; currentitem = firstvisibleitem; listviewstory.addfooterview(progressloadmore); new getstorylist().execute(); } } }); new getstorylist().execute(); } private class getstorylist extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); } @override protected void doinbackground(void... params) { .... liststory.add(...); // data added here .... return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); adapter = new storylistmenuadapter(liststory, getapplicationcontext()); listviewstory.setadapter(adapter); progressbar.setvisibility(view.gone); if(listviewstory.getfooterviewscount() > 0) { listviewstory.removefooterview(progressloadmore); if(enableloadmore) listviewstory.setselection(currentitem + 1); else listviewstory.setselection(currentitem); } loadmorestatus = true; } } } i encountered similar problems recyclerview. looked not find way how add data listview adapter users not notice refresh of listview adapter. have ideas me?
**update: add item in liststory notifydatasetchanged(). worked fine in listview not work in recyclerview. in `recyclerview' have method update data in recycleradapter:
public void additem(int position, storymenu item) { liststory.add(position, item); notifyiteminserted(position); } and call additem method after more data.
you have check if adapter == null , them create new one, if not null can execute adapter.add(items) , notifydatasetchanged() refresh listview, reyclerview.
Comments
Post a Comment