Android 多个 SimpleCursorAdapter
我正在开发一个与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个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
View
s in a customCursorAdapter
.据我所知,您无法将多个适配器附加到 ListView。不幸的是,我认为您可能需要以稍微不同的方式来处理这个问题。
取决于您实际希望应用程序如何工作,有可能有几种不同的方法。
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.
Depending on how you actually want the application to work, there could be several different approaches.