android - Keep current scroll position when update listview -


i want new data , update listview using code below, want when scroll until bottom of listview, automatically update , add new data list.

e.g: facebook, add new data bottom without scroll , keep current position

but end having problem.

1) listview updated,but scrolled top.

listview .setonscrolllistener(new onscrolllistener() {     private int currentvisibleitemcount;     private int currentscrollstate;     private int currentfirstvisibleitem;     private int totalitem;      @override     public void onscrollstatechanged(abslistview view, int scrollstate) {         this.currentscrollstate = scrollstate;         this.isscrollcompleted();     }      @override     public void onscroll(abslistview view, int firstvisibleitem,                          int visibleitemcount, int totalitemcount) {          this.currentfirstvisibleitem = firstvisibleitem;         this.currentvisibleitemcount = visibleitemcount;         this.totalitem = totalitemcount;      }     private void isscrollcompleted() {          if (totalitem - currentfirstvisibleitem == currentvisibleitemcount                 && this.currentscrollstate == scroll_state_idle) {              log.d("this is", "the end");             page = page + 1;             call_function(page);          }      } });  .... .... public void call_function(int page_number) { ... ...     listadapter adapter = new simpleadapter(                             getactivity(), user_list,                             r.layout.user, new string[] {"user","date"},                             new int[] {r.id.usr_name ,r.id.register_time});      // updating listview      setlistadapter(adapter); } 

any solution handle exceptions??

thanks in advance.

when update adapter's data can save list current selected item index , set when data rendered. this:

int index = mlist.getfirstvisibleposition(); // update stuff mlist.smoothscrolltoposition(index); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -