Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What CursorAdapter have I to use?

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?

like image 387
crbin1 Avatar asked Nov 20 '11 22:11

crbin1


People also ask

How do I use CursorAdapter?

1) CursorAdapterIn BaseAdapter, view is created in getView method; in CursorAdapter, however, view is created in newView() method and elements are populated in bindView(). In the newView() method, you simply inflate the view your custom xml and return it. In the bindView() method, you set the elements of your view.

What is CursorAdapter in Android?

An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. Adapter that exposes data from a Cursor to a ListView widget.

How many types of adapters are there in Android?

Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an AdapterView ( i.e. ListView or GridView). The common adapters are ArrayAdapter,Base Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapter.

What is cursor loader?

A CursorLoader is a specialized member of Android's loader framework specifically designed to handle cursors. In a typical implementation, a CursorLoader uses a ContentProvider to run a query against a database, then returns the cursor produced from the ContentProvider back to an activity or fragment.


2 Answers

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.

like image 129
dymmeh Avatar answered Nov 15 '22 23:11

dymmeh


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

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

like image 37
Peter Knego Avatar answered Nov 15 '22 23:11

Peter Knego