What CursorAdapter have I to use?

ぃ、小莉子 提交于 2019-12-22 04:19:24

问题


CursorAdapter have 3 constructors. Let see the guide and reference.

1) CursorAdapter(Context context, Cursor c)

This constructor is deprecated. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

2) CursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter(Context, Cursor, int).

3) CursorAdapter(Context context, Cursor c, int flags)

Recommended constructor.

flags Flags used to determine the behavior of the adapter; may be any combination of FLAG_AUTO_REQUERY and FLAG_REGISTER_CONTENT_OBSERVER.

FLAG_AUTO_REQUERY This constant is deprecated. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

FLAG_REGISTER_CONTENT_OBSERVER. This flag is not needed when using a CursorAdapter with a CursorLoader.

CursorAdapter(Context context, Cursor c, int flags) is the recommended constructor, but the possible flags are 2, one is deprecated and the other is not needed when using a CursorAdapter with a CursorLoader. If I use a CursorAdapter with a CursorLoader I have to use this constructor and pass zero as flag? And in this case is constructor the same than #1 deprecated?


回答1:


By using #1, it defaults the adapter to auto-requery. This differs from #3 because you can specify if you wish to auto-requery (which you shouldn't, per the documentation). So, no, #1 and #3 aren't the same if you pass the #3 constructor 0.




回答2:


CursorAdapter is an abstract class and as such can not be instantiated.

Also, keep in mind that the 3rd constructor is API 11+ only.




回答3:


You need to migrate with LoaderManager and Loader.

because most probably all would be deprecated. so better to use CursorLoader with LoaderManager and Loader

You can find the sample project in the below link which gets the list of apps installed in any phone.

https://github.com/alexjlockwood/AppListLoader.git

Good luck..



来源:https://stackoverflow.com/questions/8205147/what-cursoradapter-have-i-to-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!