Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out <a href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.ViewBinder.html">SimpleCursorAdapter.ViewBinder</a>.</p> <p><a href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.ViewBinder.html#setViewValue%28android.view.View,%20android.database.Cursor,%20int%29">setViewValue</a> is basically your chance to do whatever you wish with the data in your <code>Cursor</code>, including setting the background color of your views.</p> <p>For example, something like:</p> <pre><code>SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { String name = cursor.getColumnName(columnIndex); if ("Colour".equals(name)) { int color = cursor.getInt(columnIndex); view.setBackgroundColor(color); return true; } return false; } } datasource.setViewBinder(binder); </code></pre> <p><strong>Update</strong> - if you're using a custom adapter (extending <code>CursorAdaptor</code>) then the code doesn't change a whole lot. You'd be overriding <code>getView</code> and <code>bindView</code>:</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView != null) { return convertView; } /* context is the outer activity or a context saved in the constructor */ return LayoutInflater.from(context).inflate(R.id.my_row); } @Override public void bindView(View view, Context context, Cursor cursor) { int color = cursor.getInt(cursor.getColumnIndex("Colour")); view.setBackgroundColor(color); String label = cursor.getString(cursor.getColumnIndex("GenreLabel")); TextView text = (TextView) findViewById(R.id.genre_label); text.setText(label); } </code></pre> <p>You're doing a bit more manually, but it's more or less the same idea. Note that in all of these examples you might save on performance by caching the column indices instead of looking them up via strings.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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