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
Post a Comment