Question

How can I highlight a row in a ListView backed by a CursorAdapter knowing the row ID of the item?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top