Get position of an item within a ListView?

后端 未结 3 1857
無奈伤痛
無奈伤痛 2021-02-08 20:05

How would one find the position of a specific item within a ListView? (Populated by SimpleCursorAdapter).

The reason I ask: The listview is set to singleChoice mode. Whe

3条回答
  •  礼貌的吻别
    2021-02-08 20:17

    When you say, "...reselecting the item in the activity's onCreate method...", do you mean that when the user returns to the ListView activity, whatever item was previously chosen, is now currently at the top of the screen (assuming enough items appear in the list below it)?

    If so, then from onListItemClick, you should also make an effort to save the value of position, since it tells you the position in the list of the selected item. This would allow you to not need to reverse-lookup the position from the _id.

    Or is that for some reason not an option for your purposes? Do you really need to instead figure out the position from the _id?

提交回复
热议问题