显示本地数据库和远程服务的搜索结果
我有一个应用程序,将项目存储在本地数据库中,使用 ListView
显示给用户,布局中还有一个 EditText
,可用于过滤列表。所有这些都工作正常,我的问题是我还想在此列表中包含由 Web 服务 (JSON) 返回的项目。我在解析 JSON 时没有遇到问题,我的问题只是如何将 Web 服务的结果插入/添加到 ListView 中?
ListView 的数据来自 SimpleCursorAdapter 处理的游标,我只是不知道如何将 JSON 结果中的项目添加到游标(我实际上不认为您可以在执行查询之外写入游标) )。
I have an app that stores items in a local database, displayed to the user using a ListView
, also in the layout is an EditText
that can be used to filter the list. All of this works fine, my issue is I would also like to include items returned by a web service (JSON) in this list also. I'm not having an issue parsing the JSON, my issue is simply how do I insert/add the results from the web service to the ListView?
The data for the ListView comes from a cursor handled by a SimpleCursorAdapter, I just can not figure out how to add the items from the JSON results to the Cursor (I don't actually think you can write to a Cursor outside of performing a Query).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想将 JSON 结果插入本地数据库,那么一种方法是使用 ArrayAdapter 来支持 ListView。然后,您可以通过插入游标和 JSON 查询的结果来填充该数组。
希望这有帮助,
菲尔·莱洛
If you don't want to insert the JSON results into the local DB, then one approach would be to use an ArrayAdapter to back the ListView. You can then populate the array by inserting results from the cursor and the JSON query.
Hope this helps,
Phil Lello