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. Android: Binding data from a database to a CheckBox in a ListView?

Community
  • 1
  • 1
Jared
  • 1,269
  • 2
  • 10
  • 14

2 Answers2

3

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
  • 51,744
  • 11
  • 75
  • 60
0

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295