Android的SimpleCursorAdapter与LoaderManager / CursorLoader [英] Android SimpleCursorAdapter vs. LoaderManager/CursorLoader

查看:295
本文介绍了Android的SimpleCursorAdapter与LoaderManager / CursorLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何去扩展SimpleCursorAdapter以允许以下内容:

How can I go about extending SimpleCursorAdapter to allow for the following:

2片段,一个菜单一个细节。菜单ListFragment是表的列表,详细显示ListFragment针对这些表的查询结果。细节ListFragment被从菜单ListFragment选择通过一个表名。在详细ListFragment内onActivityCreated,所有记录都选入光标。此游标传递到SimpleCursorAdapter。这SimpleCursorAdapter然后设置为ListAdapter的细节ListFragment。

2 fragments, one menu one detail. Menu ListFragment is a list of tables, detail ListFragment shows the result of a query against these tables. The detail ListFragment gets passed a table name from the selection in the menu ListFragment. In onActivityCreated inside the detail ListFragment, all records are selected into a cursor. This cursor is passed into a SimpleCursorAdapter. This SimpleCursorAdapter is then set as the ListAdapter for the detail ListFragment.

我无法弄清楚是如何动态地改变SimpleCursorAdapter显示基于游标结果的列数正确。我从Cursor.getColumnNames()列名,我可以把这些插入SimpleCursorAdapter构造的String []从参数。但我怎么动态创建的int值参数必要的看法?将SimpleCursorAdapter只是还不如说是找建了一个xml布局文件IDS这种情况下工作?我是否应该转移到使用LoaderManager用CursorLoader?那将是一个更灵活的解​​决方案?

What I can't figure out is how to dynamically change the SimpleCursorAdapter to display the correct number of columns based on the cursor results. I have the column names from Cursor.getColumnNames(), and I can throw these into the String[] from parameter on the SimpleCursorAdapter constructor. But how do I dynamically create the views necessary for the int to parameter? Will SimpleCursorAdapter just not work for this situation as it is looking for ids built off an xml layout file? Should I move on to using a LoaderManager with a CursorLoader? Will that be a more flexible solution?

推荐答案

您应该移动到使用LoaderManager用CursorLoader。

You should move onto using LoaderManager with a CursorLoader.

由于 SimpleCursorAdapter 说,在部分:

此构造德precated。此选项气馁,因为它会导致应用程序的UI线程正在执行光标查询,从而可能会导致反应不佳,甚至应用程序无响应的错误。

这篇关于Android的SimpleCursorAdapter与LoaderManager / CursorLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆