Jram
Jram

Reputation: 1618

Listview getFirstVisiblePosition

I am trying to get the position of the first visible row that is entirely visible to screen. End of scrolling, if the portion of the row is visible in first row, I need to select next position. How to do this?

Upvotes: 4

Views: 5916

Answers (2)

Dheeraj Vepakomma
Dheeraj Vepakomma

Reputation: 28717

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.

Upvotes: 2

waqaslam
waqaslam

Reputation: 68177

youe need to implement OnScrollListener on 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
}

Upvotes: 0

Related Questions