Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating custom simple cursor adapter
    text
    copied!<p>I want to create a very simple cursor custom cursor adapter to facilitate changing the colors of row items on click. Using the following code </p> <pre><code>private static int save = -1; public void onListItemClick(ListView parent, View v, int position, long id) { parent.getChildAt(position).setBackgroundColor(Color.BLUE); if (save != -1 &amp;&amp; save != position){ parent.getChildAt(save).setBackgroundColor(Color.BLACK); } save = position; } </code></pre> <p>I got the code from this thread <a href="https://stackoverflow.com/a/7649880/498449">https://stackoverflow.com/a/7649880/498449</a></p> <p>I would have used a simple cursor adapter and placed the code in the onClick, but because the default list in the ListFragment reuses views, as you scroll multiple views are shown to be highlighted. Talking on IRC, it was suggested that I create a custom cursor adapter. However, I can't seem to locate the best practice how how to do this, and where the above code snippet would fit in. Could greatly appreciate the help.</p> <pre><code>public class AreaCursorAdapter extends CursorAdapter { private Context context; public AreaCursorAdapter(Context context, Cursor c) { super(context, c); // TODO Auto-generated constructor stub } @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))); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); bindView(v, context, cursor); return v; } } </code></pre> <p>I've updated the cursor adapter with some code I found online. However, I have two problems. 1. I am using a cursor loader, so I don't have a "cursor" object to pass into the constructor. 2. I'm getting a warning from Eclipse that the constructor has been deprecated.</p>
 

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