Android 多个 SimpleCursorAdapter

发布于 2024-11-07 01:26:56 字数 1100 浏览 1 评论 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 个 SimpleCursorAdapters 现在显示在我的列表中?

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

I'm working on a little App which works with a SQLite Database... i'm showing a picture (green, yellow or red) which depends on a priority.
i have 3 priorities (high, medium and low...) and i'm getting those cursors as following:

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

Then i'm calling some other stuff like this:

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

so then i have all of my stuff prepared to show on my list... but if i use setListAdapter i can only use 1 of them. since i have 3 different layouts with the different cursors, this is really pretty hard to do.
How can i get all those 3 SimpleCursorAdapters to show in my list now?

EDIT: Maybe i wasnt clear enough... All of this data is in only one table... but since i have 3 different layouts (because of the different priority colors) i need to add them seperately... or is there any other way of just saying like if the priority equals 'high' put this image in layout so i only need one SimpleCursorAdapter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2024-11-14 01:26:56

您可以创建一个VIEW,它将组合所有3个表中的数据+一个额外的列来告诉哪个表数据来自。然后,您可以从中查询并在自定义 CursorAdapter 中返回适当的行 View

You can create a VIEW that would combine data from all 3 tables + an extra column to tell which table the data came from. Then you query from it and return appropriate row Views in a custom CursorAdapter.

浴红衣 2024-11-14 01:26:56

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

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

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

To my knowledge, you would be unable to attach more than one adapter to a ListView. Unfortunately, I think you may need to approach this in a little different way.

  1. You could stick with one adapter and make sure your sorting is correct in your database query.
  2. You could create one adapter and loop through each cursor, adding items to that single adapter (probably not a Cursor Adapter but more like an ArrayAdapter).
  3. You could, I suppose, Use a LinearLayout with 3 ListViews weighted to 1 each and have 3 separately scrolling lists on the screen at one time...

Depending on how you actually want the application to work, there could be several different approaches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文