开发者

Highlight ListView row based on id

开发者 https://www.devze.com 2023-01-12 13:49 出处:网络
How can I highlight a row in a ListView backed by a CursorAdapter knowing the row ID of the开发者_如何学编程 item?If by \"highlight\" you mean \"select\", you will need to manually iterate over your C

How can I highlight a row in a ListView backed by a CursorAdapter knowing the row ID of the开发者_如何学编程 item?


If by "highlight" you mean "select", you will need to manually iterate over your Cursor, find which position corresponds to that _id value, then call setSelection() on the ListView to select the row with that position. This will only have an impact if the user is not in touch mode, as there is no concept of a selection in a ListView if the user is using the touch screen.

EDIT

Given your first comment, you will need to do several things:

  1. Extend your existing adapter class to create your own custom one
  2. Override getViewTypeCount() to return 2, since you have two types of rows (normal and special)
  3. Override getItemViewType() to return 0 or 1, depending on whether the position is the one for your desired _id or not
  4. Override bindView() and based on the item view type, inflate and tailor the row as needed
0

精彩评论

暂无评论...
验证码 换一张
取 消