What is the exact difference between CursorAdapter
and
ResourceCursorAdapter
?
Can somebody explain what are the api's that are required to override
when implementing my own ResourceCursorAdapter
?
I have gone through the ResourceCursorAdapter
documentation and able
to figure out that it's constructor takes an additional layout
parameter as compared to CursorAdapter
constructor. But I am unable to
understand what is the significance of having an additional layout
parameter in ResourceCusorAdapter
constructor.
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.
An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views. Binding occurs in two phases. First, if a SimpleCursorAdapter.
Both CursorAdapter and ResourceCursorAdapter are abstract classes. The exact difference is that ResourceCursorAdapter implements the newView method (which is abstract in the base CursorAdapter).
ResourceCursorAdapter also overrides the newDropDownView method differently, but that's not the main thing, the main thing is newView.
The extra layout in the constructor is what is used to create the view for each item, here is the newView method of ResourceCursorAdapter from the source:
/**
* Inflates view(s) from the specified XML file.
*
* @see android.widget.CursorAdapter#newView(android.content.Context,
* android.database.Cursor, ViewGroup)
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return mInflater.inflate(mLayout, parent, false);
}
Basically, if you don't use ResourceCursorAdapter, you do much the same in your own custom implementation of CursorAdapter. You're free to do more, of course, but if you have a set layout it's easier to extend ResourceCursorAdapter (it adds a bit of convenience, that's all).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With