android endless gridview logic wrong? -
follow lazy download images gridview write code add more data after 5 row scroll.
mygridviewadater extend baseadapter seem normally. , in page include gridview:
int current_page = 0; @override public void oncreate(bundle savedinstancestate) { listdishentity = dishdatabase.getalldishs(); //421 size listdishdisplay = new arraylist<dishentity>(); (int = 0; < 15; i++) { listdishdisplay.add(listdishentity.get(i)); // 15 component //first iniate gridview } }
// , display initiate data
dishimagegridviewadapter adapter = new dishimagegridviewadapter( mcontext, listdishdisplay, ""); adapter.notifydatasetchanged(); gridnutri.setadapter(adapter); gridnutri.setonscrolllistener(new onscrolllistener() { @override public void onscrollstatechanged(abslistview view, int scrollstate) { } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { int lastinscreen = firstvisibleitem + visibleitemcount; // toast.maketext(mcontext, "lastinscreen: " + lastinscreen, // 1000).show(); log.d("lastinscreen", "" + lastinscreen); if ((lastinscreen == totalitemcount) && loadingmore) { //loadingmore iniate =false // fetch next batch of feeds log.d("totalitemcount", "" + totalitemcount); new loadmorephotos().execute(); } } });
and here asytask class:
private class loadmorephotos extends asynctask {
@override protected void doinbackground(void... arg0) { try { // set loading more "true" loadingmore = true; log.d("loadingmore ", "" + loadingmore); // increment current page current_page += 1; // next page request } catch (exception e) { log.d("exception ", "" + e.getmessage()); } return null; } @override protected void onpreexecute() { // todo auto-generated method stub // show bottom progress bar (spinner) while loading more photos linlaprogressbar.setvisibility(view.visible); // toast.maketext(mcontext, "cac", 1000).show(); } @override protected void onpostexecute(void result) { // listview current position - used maintain scroll position int currentposition = gridnutri.getfirstvisibleposition(); // append new data arraylist , set adapter // listview // listdishdisplay.clear(); (int = ((current_page - 1) * tempdishunitscroll); < current_page * tempdishunitscroll; i++) { listdishdisplay.add(listdishentity.get(i)); } log.d("current_page ", "" + current_page); dishimagegridviewadapter adapter = new dishimagegridviewadapter( mcontext, listdishdisplay, ""); adapter.notifydatasetchanged(); gridnutri.setadapter(adapter); // setting new scroll position gridnutri.setselection(currentposition + 1); // set loadingmore "false" after adding new feeds existing // list loadingmore = false; log.d("loadingmore ", "" + loadingmore); linlaprogressbar.setvisibility(view.gone); } }
with each scroll end, show next 5 row ( 15 component). seem rune nomally 4 times. see log :
08-18 05:41:10.092: d/fapfap(1790): 9 08-18 05:41:10.112: d/onscroll loadingmore(1790): true 08-18 05:41:10.112: d/fapfap(1790): 12 08-18 05:41:10.236: d/onscroll loadingmore(1790): true 08-18 05:41:10.236: d/fapfap(1790): 12 08-18 05:41:10.248: d/onscroll loadingmore(1790): true 08-18 05:41:10.248: d/fapfap(1790): 12 08-18 05:41:10.264: d/onscroll loadingmore(1790): true 08-18 05:41:10.264: d/fapfap(1790): 12 08-18 05:41:10.276: d/onscroll loadingmore(1790): true 08-18 05:41:10.276: d/fapfap(1790): 12 08-18 05:41:10.296: d/onscroll loadingmore(1790): true 08-18 05:41:10.296: d/fapfap(1790): 12 08-18 05:41:10.316: d/onscroll loadingmore(1790): true 08-18 05:41:10.316: d/fapfap(1790): 12 08-18 05:41:10.336: d/onscroll loadingmore(1790): true 08-18 05:41:10.336: d/fapfap(1790): 15 08-18 05:41:10.336: d/totalitemcount(1790): 15 08-18 05:41:10.344: d/onscroll loadingmore(1790): true 08-18 05:41:10.344: d/loadingmore(1790): true 08-18 05:41:10.344: d/fapfap(1790): 15 08-18 05:41:10.344: d/totalitemcount(1790): 15 08-18 05:41:10.348: d/loadingmore(1790): true 08-18 05:41:10.456: d/onscroll loadingmore(1790): true 08-18 05:41:10.456: d/fapfap(1790): 15 08-18 05:41:10.456: d/totalitemcount(1790): 15 08-18 05:41:10.460: d/loadingmore(1790): true 08-18 05:41:10.468: d/current_page(1790): 2 ///// why 08-18 05:41:10.468: d/loadingmore(1790): false ///// current_page 08-18 05:41:10.468: d/current_page(1790): 3 ///// increase continuesly? 08-18 05:41:10.468: d/loadingmore(1790): false ///// not know why @@ 08-18 05:41:10.468: d/current_page(1790): 4 ///// 08-18 05:41:10.468: d/loadingmore(1790): false 08-18 05:41:10.480: d/onscroll loadingmore(1790): false
and max of data size 60, not 421 :(
08-18 06:02:04.476: d/onscroll loadingmore(1790): false 08-18 06:02:04.476: d/fapfap(1790): 60 08-18 06:02:04.480: d/onscroll loadingmore(1790): false 08-18 06:02:04.480: d/fapfap(1790): 60 08-18 06:02:04.480: d/onscroll loadingmore(1790): false 08-18 06:02:04.480: d/fapfap(1790): 60 08-18 06:02:04.484: d/onscroll loadingmore(1790): false 08-18 06:02:04.484: d/fapfap(1790): 60 08-18 06:02:04.568: d/onscroll loadingmore(1790): false 08-18 06:02:04.572: d/fapfap(1790): 60
Comments
Post a Comment