Android ListView: get data index of visible item

Posted by Mayra on Stack Overflow See other posts from Stack Overflow or by Mayra
Published on 2010-01-04T19:52:51Z Indexed on 2010/06/17 5:33 UTC
Read the original article Hit count: 1331

Filed under:
|

I have an Android ListView created with a SimpleAdapter that has more items in it than fit in the screen. After the list has been scrolled, I need to get the position in the data model of the first visible item in the list.

Basically I want a function like: listView.getChildAt(0).getPositionInDataModel().

Adapter has a few functions in it, like getItemId(position) that looked useful; however, the SimpleAdapter implementation just returns the passed in position, not a row id like I'd hoped.

A brute force solution would be to get the View at index 0, and compare it to the view for each item in the adapter. However, there doesn't seem to be an easy way to get the view for a particular position from the adapter.

Anyone have any thoughts?

© Stack Overflow or respective owner

Related posts about android

Related posts about listview