what is cursor adapter?

Asked 06-Apr-2018
Viewed 942 times

1 Answer


0

Cursor Adapter In Android
CursorAdapter classes is used to display data from a SQLite database. And simpleCursorAdapter classes is simpler adapter that can’t use your own custom xml layout file and you don’t have the control of the layout file. If you want to add custom xml layout file, then android provides CursorAdapter classes.
CursorAdapter is most useful for, when you are using listView.  and the resource of a listview is coming from database and you have full control over the binding of data values to layout control files. CursorAdapter uses, newView() method to inflate the view and return it and uses bindView() method to set the component or elements of your view.

Here, show the relation between ContentProvider(), SimpleCursorAdapter() and the view.

what is cursor adapter?


In CursorAdapter, firstly you can create new class which extends CursorAdapter and give it any name. This new adapter class must be inherit the CursorAdapter class is as follows-

public class MyCursorAdapterExample extends CursorAdapter {
    // Calling Default constructor
    public MyCursorAdapterExample(Context context, Cursor cursor, int flags) {
        ... ...............
        ....................
    }
    public void bindView(View view, Context context, Cursor cursor) {
        ... ...................
        ......................
    }
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        ... ..................
        .....................
        return null;
    }
}