tags:

views:

71

answers:

2

I am curious if there is a way to bind more then one db column to a resource. I need to bind more information to R.id.secondLine then just the difficulty column. But I'm unsure how to go about this? I'm currently subclassing SimpleCursorAdapter. Should I subclass another adapter? If so How to do I go about it?

    Cursor activityHikes = mDbAdapter.fetchAllHikes(false);
    startManagingCursor(activityHikes);

    String[] from = new String[] { ActivityHike.NAME, ActivityHike.DIFFICULTY, ActivityHike.THUMBNAIL};

    int[] to = new int[]{R.id.mainText, R.id.secondLine, R.id.icon};

    HikeAdapter hikes = new HikeAdapter(this, R.layout.hike_row, activityHikes, from, to);
    ListView list = (ListView) this.findViewById(R.id.hikelist);
    list.setAdapter(hikes);

Thanks

For anyone who has this same problem this link helped me alot too. http://stackoverflow.com/questions/1505751/android-binding-data-from-a-database-to-a-checkbox-in-a-listview

A: 

I would implement your own ViewBinder and pass that to your SimpleCursorAdapter. This gives you full access to the cursor when setting the values of each View.

mbaird
+2  A: 

I don't think you can bind more than one column to a view using SimpleCursorAdapter. Your best bet would be to subclass CursorAdapter and implement bindView to do any special formatting you want to the text field.

Erich Douglass
Thanks for the help. It worked out great!
Jared