开发者

CursorAdapter vs ResourceCursorAdapter

开发者 https://www.devze.com 2023-01-10 18:19 出处:网络
What is the exact difference between CursorAdapter and ResourceCursorAdapter? Can somebody explain what are the api\'s that are required to override

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 paramete开发者_开发百科r as compared to CursorAdapter constructor. But I am unable to understand what is the significance of having an additional layout parameter in ResourceCusorAdapter constructor.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消