【问题标题】:How to bind more then one column to a textview如何将多于一列绑定到文本视图
【发布时间】:2010-01-22 17:02:04
【问题描述】:

我很好奇是否有一种方法可以将多个 db 列绑定到资源。我需要将更多信息绑定到 R.id.secondLine 然后只是难度列。但我不确定该怎么做?我目前正在继承 SimpleCursorAdapter。我应该继承另一个适配器吗?如果是,我该怎么办?

    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);

谢谢

对于遇到同样问题的任何人,此链接也对我有很大帮助。 Android: Binding data from a database to a CheckBox in a ListView?

【问题讨论】:

    标签: android sqlite


    【解决方案1】:

    我认为您不能使用SimpleCursorAdapter 将多个列绑定到一个视图。最好的办法是继承 CursorAdapter 并实现 bindView 以对文本字段进行任何特殊格式设置。

    【讨论】:

      【解决方案2】:

      我会实现您自己的 ViewBinder 并将其传递给您的 SimpleCursorAdapter。这使您可以在设置每个视图的值时完全访问光标。

      【讨论】:

        猜你喜欢
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 2013-11-25
        • 2011-08-10
        • 2010-09-21
        • 1970-01-01
        • 1970-01-01
        • 2020-01-21
        相关资源
        最近更新 更多