4

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?

Daniel Hiller
  • 3,325
  • 3
  • 22
  • 33
Jram
  • 1,508
  • 1
  • 10
  • 7

2 Answers2

2
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.

Community
  • 1
  • 1
Dheeraj Vepakomma
  • 19,992
  • 13
  • 70
  • 98
  • This seems to work for me. But still I needed only the value for "y". So I didn't try the last if condition.Apart from that, the condition seems to work fine. – Andro Selva Apr 10 '12 at 08:15
0

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
}
waqaslam
  • 66,380
  • 16
  • 161
  • 174
  • but i want to check ,whether the user can see the first row (firstVisibleItem) entirely. for example when you started scroll a list, you can see only little part in first row & last row. if you want to see entire portion of the first/bottom row, you need to scroll it up/down little future. – Jram Mar 17 '12 at 22:44
  • as long as even 1dp of an item is visible, it is considered as visible by `firstVisibleItem` – waqaslam Mar 17 '12 at 23:19