Reputation: 1443
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.
Upvotes: 2
Views: 1056
Reputation: 11032
Simple solution would be to set the id to child item in bind view
@Override
public void bindView(View view, final Context context, Cursor cursor {
.....
convertView.setId(id);
}
Later from the activity you can find this view by id and get the position
View yourChildViewWithSpecifiedId = yourListView.findViewById(id);
int position = yourListView.getPositionForView(yourChildViewWithSpecifiedId);
Upvotes: 0
Reputation: 86948
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...).
Upvotes: 1