0

我正在开发一个与 SQLite 数据库一起使用的小应用程序...我正在显示取决于优先级的图片(绿色、黄色或红色)。我有 3 个优先级(高、中和低......),我得到的光标如下:

cursorh = dbAdapter.fetchAllHighPrio();
cursorm = dbAdapter.fetchAllMedPrio();
cursorl = dbAdapter.fetchAllLowPrio();

然后我打电话给其他一些像这样的东西:

startManagingCursor(cursorh);
startManagingCursor(cursorm);
startManagingCursor(cursorl);

String[] from = new String[] { TodoDbAdapter.KEY_SUMMARY };
int[] to = new int[] { R.id.label };

SimpleCursorAdapter noteh = new SimpleCursorAdapter(this,
        R.layout.todo_row_high, cursorh, from, to);
SimpleCursorAdapter notem = new SimpleCursorAdapter(this,
        R.layout.todo_row_med, cursorm, from, to);
SimpleCursorAdapter notel = new SimpleCursorAdapter(this,
        R.layout.todo_row_low, cursorl, from, to);

所以我已经准备好在我的列表中显示我的所有东西......但如果我使用 setListAdapter 我只能使用其中的 1 个。因为我有 3 种不同的布局和不同的光标,所以这真的很难做到。我怎样才能让所有这 3 个 SimpleCursorAdapter 现在显示在我的列表中?

编辑:也许我不够清楚......所有这些数据都只在一个表中......但由于我有 3 种不同的布局(因为不同的优先级颜色)我需要单独添加它们......或者有没有换句话说,如果优先级等于“高”,则将此图像放入布局中,所以我只需要一个 SimpleCursorAdapter?

4

2 回答 2

0

据我所知,您将无法将多个适配器附加到 ListView。不幸的是,我认为您可能需要以不同的方式来解决这个问题。

  1. 您可以坚持使用一个适配器并确保您的排序在数据库查询中是正确的。
  2. 您可以创建一个适配器并循环遍历每个光标,将项目添加到该单个适配器(可能不是光标适配器,但更像是 ArrayAdapter)。
  3. 我想,你可以使用一个 LinearLayout,其中 3 个 ListView 的权重分别为 1,并且一次在屏幕上有 3 个单独的滚动列表......

根据您实际希望应用程序如何工作,可能有几种不同的方法。

于 2011-05-15T18:52:23.887 回答
0

您可以创建一个VIEW组合来自所有 3 个表的数据 + 一个额外的列来判断数据来自哪个表。然后您从中查询并View在 custom 中返回适当的row CursorAdapter

于 2011-05-15T20:37:23.190 回答