Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should be able to do it about that way:</p> <pre><code>class YourListFragment extends ListFragmentOrSomethingElse { private AreaCursorAdapter mAdapter; @Override public void onCreate() { mAdapter = new AreaCursorAdapter(this, null); setListAdapter(mAdapter); } @Override public void onListItemClick(ListView parent, View v, int position, long id) { mAdapter.setSelectedPosition(position); } @Override public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) { mAdapter.swapCursor(cursor); // should reset that here maybe mAdapter.setSelectedPosition(-1); } } public class AreaCursorAdapter extends CursorAdapter { private Context context; private int mSelectedPosition; LayoutInflater mInflater; public AreaCursorAdapter(Context context, Cursor c) { // that constructor should be used with loaders. super(context, c, 0); mInflater = LayoutInflater.from(context); } public void setSelectedPosition(int position) { mSelectedPosition = position; // something has changed. notifyDataSetChanged(); } @Override public void bindView(View view, Context context, Cursor cursor) { TextView list_item = (TextView)view.findViewById(android.R.id.text1); list_item.setText(cursor.getString(cursor.getColumnIndex(INDICATOR_NAME))); int position = cursor.getPosition(); // that should be the same position if (mSelectedPosition == position) { view.setBackgroundColor(Color.RED); } else { view.setBackgroundColor(Color.WHITE); } } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View v = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); // edit: no need to call bindView here. That's done automatically return v; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload