I have done the notepad tutorial of the google webside. There are these tree strings:
public static final String KEY_TITLE = "title";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";
I only put the values “0”, “1”, “2”, “3” in my KEY_TITLE. Instead of showing the strings in a TextView of my Listview, I want to show the images from this array:
private int icons[] = new int[] {R.drawable.icon1,
R.drawable.icon2, R.drawable.icon3, R.drawable.icon4};
e.g. If KEY_TITLE ist “0” I want to show the the image icon1. etc….
Now I have the problem, that the SimpleCursorAdapter can only map to TextViews. How can I tell the SimpleCursorAdapter, that it has to map the string values to the number of icons in my icons[]-string?
Can anybody help me, how to write a new SimpleCursorAdapter? Or is it not necessary?
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
int[] to = new int[]{R.id.image};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
Thanks a lot.
Felix
Hi FelixA why a SimpleAdapter?
If i may make a suggestion switch to CustomBasAdapter, it gices you more options to tweak for later use, also adding icons, images etc.
Follow the description on this site to make the adapter.
You can later on tweak it and add the icons pictures etc.