Listview getFirstVisiblePosition

I am trying to get the position of the first visible line that is completely visible to the screen. End of scrolling, if part of the line is visible in the first line, I need to select the next position. How to do it?

+4
source share
2 answers
int index = list.getFirstVisiblePosition(); View v = list.getChildAt(0); int y = (v == null) ? 0 : v.getTop(); if (y > 0 && index + 1 < list.getCount()) { ++index; } 

Adapted from this answer .

+2
source

you need to implement OnScrollListener in your ListView and then override the following method to get the first visible item:

 @Override public void onScroll(AbsListView view, int firstVisibleItem, final int visibleItemCount, final int totalItemCount) { //"firstVisibleItem" is the value you need to look for } 
0
source

Source: https://habr.com/ru/post/1402015/


All Articles