Search code examples
androidandroid-listviewandroid-cursoradapter

Find listview position based on id


I have a ListView displaying data from a SimpleCursorAdapter. I have the id value and I want the position in the list, the opposite of getItemId(position). Is there such a functionality?

I know how to implement it (don't bother show code) but I just can't find it and it seems like an obvious method.


Solution

  • Brought up from comments

    There is no method like this for the built-in adapters. If your ListView is sorted by the row ids then you can use a binary search (fast!), otherwise you're probably stuck with an exhaustive search (slow...).