Android: Changing an ImageView src depending on database field data
<p>I'm quite new to Android development (started 2 days ago) and have been through a number of tutorials already.  I'm building a test app from the NotePad exercise (<a href="http://developer.android.com/resources/tutorials/notepad/index.html" rel="nofollow">Link to tutorial</a>) in the Android SDK and as part of the list of notes I want to display a different image depending on the contents of a database field i've called "notetype".  I'd like this image to appear in the List view before each notepad entry.</p>

<p>The code in my .java file is:</p>

<pre><code>private void fillData() {
    Cursor notesCursor = mDbHelper.fetchAllNotes();

    notesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(notesCursor);

    String[] from = new String[]{NotesDbAdapter.KEY_NOTENAME, NotesDbAdapter.KEY_NOTETYPE};

    int[] to = new int[]{R.id.note_name, R.id.note_type};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
            new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
    setListAdapter(notes);
}
</code></pre>

<p>And my layout xml file (notes_row.xml) looks like this:</p>

<pre><code>&lt;ImageView android:id="@+id/note_type"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/default_note"/&gt;
&lt;TextView android:id="@+id/note_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/&gt;
</code></pre>

<p>I just really have no clue how I'd go about fetching the right drawable depending on the type of note that has been selected.  At the moment I have the ability to select the type from a Spinner, so what gets stored in the database is an integer.  I've created some images that correspond to these integers but it doesn't seem to pick things up.</p>

<p>Any help would be appreciated.  If you need more info then please let me know.</p>
