在Android中以单父布局显示两个表的ListView?
有很多关于创建 ListView 以显示单个表中的内容的教程。 (以这个为例: http://thinkandroid.wordpress.com /2010/01/09/simplecursoradapters-and-listviews/)
我的问题是我想在单个 LinearLayout 父级中显示两个 ListView。 ListViews 将从同一数据库中的两个不同表中绘制。有人会向我指出一个教程,告诉我如何做到这一点(希望以一种干净、干燥的方式)吗?
我可以使用多个 SimpleCursorAdapter 吗?布局怎么样?它如何知道将物品放置在哪里?
There are a lot of tutorials for creating a ListView to display contents from a single table. (Take this one for example: http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/)
My problem is that I'd like to display two ListViews in a single LinearLayout parent. The ListViews will draw from two different tables in the same database. Will anyone point me to a tutorial that tells me how to do that (in, hopefully, a clean, DRY way)?
Can I use multiple SimpleCursorAdapters? What about the layouts? How will it know where to place the items?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无需使用单独的 ListViews/CursorAdapters,只需执行 JOIN 在您的表上查找您想要的数据,您将得到一个游标。那么你只需要处理一个ListView和一个适配器。
There's no need to use separate ListViews/CursorAdapters, just do a JOIN on your tables for the data you want, and you'll get a single Cursor back. Then you only have to deal with one ListView and one adapter.
您可以创建这样的布局(垂直
LinearLayout
中的两个相同大小的列表):然后您只需在活动中使用它们:
也许您可以在这两个列表之间插入一条彩色线,这样用户就不会'不要将该列表混淆为单个列表。
You can create a layout like this (two equal sized lists in a vertical
LinearLayout
):Then you just use them in your activity:
Maybe you could insert a colored line between those two list so the user doesn't confuse the list as a single one.
您可以创建一个适配器,它将查询两个源并组合数据,然后使用单个列表视图显示它。
You can create a single adapter which will query both the sources and combine the data and then display it using a single listview.