I am trying to create a single-choice (e.g., radio button) list of items that are queried from a database. To work with the currently selected row, I need to use the getCheckedItemPosition() and setItemChecked() methods of ListView.
I have a ListView that has a SimpleCursorAdapter set on it. When I retrieve the currently selected item, I have its row ID from the database, which I need to use to find the appropriate item and manually set it to be selected via the aforementioned methods. In other words, I need to map the status of a row ID to a necessarily monotonic row ID (because the setItemChecked() method accepts a position ID, not a database row ID, and in my database I can remove items).
So is there a way I can get a position id from a table row id? I’d rather not resort to doing a search if possible.
Thanks.
I ended up just creating a simple method that searches through all the items (which are assumed to be in order):
Edit: Use this code by doing something like this: