Gizmo
Gizmo

Reputation: 941

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?

Upvotes: 5

Views: 4470

Answers (1)

Lalit Poptani
Lalit Poptani

Reputation: 67286

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.

Upvotes: 10

Related Questions