开发者

How to bind more then one column to a textview

开发者 https://www.devze.com 2022-12-17 16:14 出处:网络
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 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 d开发者_JAVA技巧o 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消