android - How to use getLastVisiblePosition? -


public void ongroupupdated(newgroupmessage msg) {     if (!msg.getgroupid().equals(mgroupid)) {         return;     } else {         boolean lastitemvisible = mlist.getlastvisibleposition() == madapter.getcount() - 2;         updateconversation();         if (lastitemvisible) {             smoothscrolltolast();         }     } } 

i use above code judge if last item of listview visible. if visible, scroll list bottom.

it works, don't know why must use madapter.getcount() - 2 instead of madapter.getcount() - 1. sure header view count zero.

the listview doesn't contains footer views.

override onscroll method , following:

 @override     public void onscroll(abslistview view, int firstvisibleitem,                          int visibleitemcount, int totalitemcount) {          if (listview.getlastvisibleposition() == listview.getadapter()                 .getcount() - 1                 && listview.getchildat(listview.getchildcount() - 1) != null                 && listview.getchildat(listview.getchildcount() - 1)                         .getbottom() <= listview.getheight()) {             //put code want execute after reaching last position         }     } 

probably adding footerview @ end of listview. in order skip footerview position have -2


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -