【问题标题】:Simple Cursor Adapter sections简单光标适配器部分
【发布时间】:2013-10-18 00:17:43
【问题描述】:

我正在使用简单的光标适配器来填充列表视图。我的数据来自 sqlyte 数据库,我有两个数据。如何在列表视图中添加部分(标题)。

我搜索了很多,但使用简单的光标适配器找不到合适的部分示例。任何帮助是极大的赞赏。这是我的例子。

startManagingCursor(光标);

String[] from = {"Label","_id"};

int[] to = new int[]{R.id.Text1};

SimpleCursorAdapter cursorAdapter =
    new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

listContent.setAdapter(cursorAdapter);

我需要添加部分,例如

第 1 节 橙子 香蕉 苹果 性别 2 红色的 蓝色的 黑色的 第 3 节 早餐 午餐

【问题讨论】:

标签: android


【解决方案1】:

这实际上很难做到,因为您需要重新映射光标位置。有一个图书馆可以帮助你做到这一点。以下是可用于通过此库实现按字母顺序排列的代码。

@Override 
protected Object getSectionFromCursor(Cursor cursor) {
    int columnIndex = cursor.getColumnIndex("Label");
    String name = cursor.getString(columnIndex);
    return name.toUpperCase().substring(0, 1); 
}

还可以查看他们按部门对员工进行排序的示例应用。

https://github.com/twotoasters/SectionCursorAdapter

【讨论】:

猜你喜欢
  • 2016-12-13
  • 1970-01-01
  • 2011-10-03
  • 2011-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多