Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CursorAdapter vs ResourceCursorAdapter

Tags:

android

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.

like image 887
cppdev Avatar asked Aug 10 '10 09:08

cppdev


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 simple cursor adapter in android?

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.


1 Answers

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).

like image 70
Charlie Collins Avatar answered Oct 18 '22 11:10

Charlie Collins