Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an event when a ListView item is visible or not

I was wondering if there is some kind of OnVisibilyChangeListener for views in a ListView because i would like to have a method called every time a ListView item change its visibility.

I know about the OnPreDrawListener to check if the view is gonna be visible. But how can i check if the view gets scrolled out of the visible screen area?

like image 959
Gizmo Avatar asked Jul 31 '13 07:07

Gizmo


1 Answers

You can implement OnScrollListener for ListView and override onScrollStateChanged(AbsListView view, int scrollState) and onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) and get the ListView item that is visible.

onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) is the method that will help you to know which row of ListView is visible by using value of firstVisibleItem and visibleItemCount.

like image 129
Lalit Poptani Avatar answered Nov 08 '22 08:11

Lalit Poptani