Android: Changing an ImageView src depending on database field data -
I am quite new to Android development (started 2 days ago) and already done through several tutorials. is. I am preparing a test app from the Notepad Workout (in Android SDK) and as part of the list of notes, I want to display a different image based on the contents of the database field called "No Type". I would like this image to appear in the list view before each notepad entry.
The code in my .java file is:
private zero fillData () {cursor notes = MDBHlp; fatalnotes (); Notes = MDBHLper.FatNalotes (); StartManagingCursor (notesCursor); String [] = new string [] {NotesDbAdapter.KEY_NOTENAME, NotesDbAdapter.KEY_NOTETYPE}; Int for [] = new int [] {R.id.note_name, R.id.note_type}; // Now create a simple cursor adapter and set it to display simple cursor adapter notes = new simple cursor adapter (from it, R. layout.notes_o, from notices, from); SetListAdapter (Notes); }
and my layout xml file (note_ro.xml) looks like this:
Android: Image = "id =" @ + id / note_type "Android: layout_width =" fill_perrent "android: layout_height =" wrap-content "Android: src =" @drawable / default_not "/> & gt; TextView Android: id =" @ + id / note_name "Android: layout_width = "Fill_parent" android: layout_height = "wrap_content" />
I do not really have any clue about what type of note I choose to get the right documentary I want to know about the field. At the moment I have the ability to select type from the spinner, so whatever is stored in the database is an integer. I have created some images that are in line with these integers but pick them up
Any help will be appreciated. Please tell me if you need more information.
You can see a viewfinder
This example should help:
Private class MyViewBinder implements SimpleCursorAdapter.ViewBinder {Public Boolean Set ViewValue (View View, Cursor Cursor, int column index) {int viewId = view.getId (); Switch (View ID) {Case RID.Not_New: TextViewNotName = (TextView) View; NoteName.setText (Cursor.getString (columnIndex)); break; Case R.id.note_type: ImageView noteTypeIcon = (ImageView) view; Int Notip = Cursor.GetEngineer (Column Index); Switch (Notepip) {Case 1: Notepip Icon. Sets Image Resource (RDRA Breakdown; Case 2: Notip Icon. Set Image Resource (Arrowable.orimage); Breakdown; etc ... break;}}
< / Pre>}
Then add it to
note with setViewBinder (new MyViewBinder ()) in your adapter;
Comments
Post a Comment