public abstract class

CursorAdapter

extends BaseAdapter

implements androidx.cursoradapter.widget.CursorFilter.CursorFilterClient

 java.lang.Object

↳BaseAdapter

↳androidx.cursoradapter.widget.CursorAdapter

Subclasses:

SimpleCursorAdapter, ResourceCursorAdapter

Gradle dependencies

compile group: 'androidx.cursoradapter', name: 'cursoradapter', version: '1.0.0'

  • groupId: androidx.cursoradapter
  • artifactId: cursoradapter
  • version: 1.0.0

Artifact androidx.cursoradapter:cursoradapter:1.0.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.cursoradapter:cursoradapter com.android.support:cursoradapter

Androidx class mapping:

androidx.cursoradapter.widget.CursorAdapter android.support.v4.widget.CursorAdapter

Overview

Static library support version of the framework's . Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Summary

Fields
public static final intFLAG_AUTO_REQUERY

If set the adapter will call requery() on the cursor whenever a content change notification is delivered.

public static final intFLAG_REGISTER_CONTENT_OBSERVER

If set the adapter will register a content observer on the cursor and will call CursorAdapter.onContentChanged() when a notification comes in.

protected booleanmAutoRequery

This field should be made private, so it is hidden from the SDK.

protected androidx.cursoradapter.widget.CursorAdapter.ChangeObservermChangeObserver

This field should be made private, so it is hidden from the SDK.

protected ContextmContext

This field should be made private, so it is hidden from the SDK.

protected CursormCursor

This field should be made private, so it is hidden from the SDK.

protected androidx.cursoradapter.widget.CursorFiltermCursorFilter

This field should be made private, so it is hidden from the SDK.

protected DataSetObservermDataSetObserver

This field should be made private, so it is hidden from the SDK.

protected booleanmDataValid

This field should be made private, so it is hidden from the SDK.

protected FilterQueryProvidermFilterQueryProvider

This field should be made private, so it is hidden from the SDK.

protected intmRowIDColumn

This field should be made private, so it is hidden from the SDK.

Constructors
publicCursorAdapter(Context context, Cursor c)

Constructor that always enables auto-requery.

publicCursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor that allows control over auto-requery.

publicCursorAdapter(Context context, Cursor c, int flags)

Recommended constructor.

Methods
public abstract voidbindView(View view, Context context, Cursor cursor)

Bind an existing view to the data pointed to by cursor

public voidchangeCursor(Cursor cursor)

Change the underlying cursor to a new cursor.

public java.lang.CharSequenceconvertToString(Cursor cursor)

Converts the cursor into a CharSequence.

public intgetCount()

public CursorgetCursor()

Returns the cursor.

public ViewgetDropDownView(int position, View convertView, ViewGroup parent)

public FiltergetFilter()

public FilterQueryProvidergetFilterQueryProvider()

Returns the query filter provider used for filtering.

public java.lang.ObjectgetItem(int position)

public longgetItemId(int position)

public ViewgetView(int position, View convertView, ViewGroup parent)

public booleanhasStableIds()

protected voidinit(Context context, Cursor c, boolean autoRequery)

public ViewnewDropDownView(Context context, Cursor cursor, ViewGroup parent)

Makes a new drop down view to hold the data pointed to by cursor.

public abstract ViewnewView(Context context, Cursor cursor, ViewGroup parent)

Makes a new view to hold the data pointed to by cursor.

protected voidonContentChanged()

Called when the on the cursor receives a change notification.

public CursorrunQueryOnBackgroundThread(java.lang.CharSequence constraint)

Runs a query with the specified constraint.

public voidsetFilterQueryProvider(FilterQueryProvider filterQueryProvider)

Sets the query filter provider used to filter the current Cursor.

public CursorswapCursor(Cursor newCursor)

Swap in a new Cursor, returning the old Cursor.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

protected boolean mDataValid

This field should be made private, so it is hidden from the SDK.

protected boolean mAutoRequery

This field should be made private, so it is hidden from the SDK.

protected Cursor mCursor

This field should be made private, so it is hidden from the SDK.

protected Context mContext

This field should be made private, so it is hidden from the SDK.

protected int mRowIDColumn

This field should be made private, so it is hidden from the SDK.

protected androidx.cursoradapter.widget.CursorAdapter.ChangeObserver mChangeObserver

This field should be made private, so it is hidden from the SDK.

protected DataSetObserver mDataSetObserver

This field should be made private, so it is hidden from the SDK.

protected androidx.cursoradapter.widget.CursorFilter mCursorFilter

This field should be made private, so it is hidden from the SDK.

protected FilterQueryProvider mFilterQueryProvider

This field should be made private, so it is hidden from the SDK.

public static final int FLAG_AUTO_REQUERY

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 android.app.LoaderManager with a .

If set the adapter will call requery() on the cursor whenever a content change notification is delivered. Implies CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER.

public static final int FLAG_REGISTER_CONTENT_OBSERVER

If set the adapter will register a content observer on the cursor and will call CursorAdapter.onContentChanged() when a notification comes in. Be careful when using this flag: you will need to unset the current Cursor from the adapter to avoid leaks due to its registered observers. This flag is not needed when using a CursorAdapter with a .

Constructors

public CursorAdapter(Context context, Cursor c)

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 android.app.LoaderManager with a .

Constructor that always enables auto-requery.

Parameters:

c: The cursor from which to get the data.
context: The context

public CursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter.CursorAdapter(Context, Cursor, int). When using this constructor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER will always be set.

Parameters:

c: The cursor from which to get the data.
context: The context
autoRequery: If true the adapter will call requery() on the cursor whenever it changes so the most recent data is always displayed. Using true here is discouraged.

public CursorAdapter(Context context, Cursor c, int flags)

Recommended constructor.

Parameters:

c: The cursor from which to get the data.
context: The context
flags: Flags used to determine the behavior of the adapter; may be any combination of CursorAdapter.FLAG_AUTO_REQUERY and CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER.

Methods

protected void init(Context context, Cursor c, boolean autoRequery)

Deprecated: Don't use this, use the normal constructor. This will be removed in the future.

public Cursor getCursor()

Returns the cursor.

Returns:

the cursor.

public int getCount()

See also:

public java.lang.Object getItem(int position)

See also:

public long getItemId(int position)

See also:

public boolean hasStableIds()

public View getView(int position, View convertView, ViewGroup parent)

See also:

public View getDropDownView(int position, View convertView, ViewGroup parent)

public abstract View newView(Context context, Cursor cursor, ViewGroup parent)

Makes a new view to hold the data pointed to by cursor.

Parameters:

context: Interface to application's global information
cursor: The cursor from which to get the data. The cursor is already moved to the correct position.
parent: The parent to which the new view is attached to

Returns:

the newly created view.

public View newDropDownView(Context context, Cursor cursor, ViewGroup parent)

Makes a new drop down view to hold the data pointed to by cursor.

Parameters:

context: Interface to application's global information
cursor: The cursor from which to get the data. The cursor is already moved to the correct position.
parent: The parent to which the new view is attached to

Returns:

the newly created view.

public abstract void bindView(View view, Context context, Cursor cursor)

Bind an existing view to the data pointed to by cursor

Parameters:

view: Existing view, returned earlier by newView
context: Interface to application's global information
cursor: The cursor from which to get the data. The cursor is already moved to the correct position.

public void changeCursor(Cursor cursor)

Change the underlying cursor to a new cursor. If there is an existing cursor it will be closed.

Parameters:

cursor: The new cursor to be used

public Cursor swapCursor(Cursor newCursor)

Swap in a new Cursor, returning the old Cursor. Unlike CursorAdapter.changeCursor(Cursor), the returned old Cursor is not closed.

Parameters:

newCursor: The new cursor to be used.

Returns:

Returns the previously set Cursor, or null if there was not one. If the given new Cursor is the same instance is the previously set Cursor, null is also returned.

public java.lang.CharSequence convertToString(Cursor cursor)

Converts the cursor into a CharSequence. Subclasses should override this method to convert their results. The default implementation returns an empty String for null values or the default String representation of the value.

Parameters:

cursor: the cursor to convert to a CharSequence

Returns:

a CharSequence representing the value

public Cursor runQueryOnBackgroundThread(java.lang.CharSequence constraint)

Runs a query with the specified constraint. This query is requested by the filter attached to this adapter. The query is provided by a . If no provider is specified, the current cursor is not filtered and returned. After this method returns the resulting cursor is passed to CursorAdapter.changeCursor(Cursor) and the previous cursor is closed. This method is always executed on a background thread, not on the application's main thread (or UI thread.) Contract: when constraint is null or empty, the original results, prior to any filtering, must be returned.

Parameters:

constraint: the constraint with which the query must be filtered

Returns:

a Cursor representing the results of the new query

See also: CursorAdapter.getFilter(), CursorAdapter.getFilterQueryProvider(), CursorAdapter

public Filter getFilter()

public FilterQueryProvider getFilterQueryProvider()

Returns the query filter provider used for filtering. When the provider is null, no filtering occurs.

Returns:

the current filter query provider or null if it does not exist

See also: CursorAdapter, CursorAdapter.runQueryOnBackgroundThread(CharSequence)

public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider)

Sets the query filter provider used to filter the current Cursor. The provider's method is invoked when filtering is requested by a client of this adapter.

Parameters:

filterQueryProvider: the filter query provider or null to remove it

See also: CursorAdapter.getFilterQueryProvider(), CursorAdapter.runQueryOnBackgroundThread(CharSequence)

protected void onContentChanged()

Called when the on the cursor receives a change notification. The default implementation provides the auto-requery logic, but may be overridden by sub classes.

See also:

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.cursoradapter.widget;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.FilterQueryProvider;
import android.widget.Filterable;

import androidx.annotation.RestrictTo;

/**
 * Static library support version of the framework's {@link android.widget.CursorAdapter}.
 * Used to write apps that run on platforms prior to Android 3.0.  When running
 * on Android 3.0 or above, this implementation is still used; it does not try
 * to switch to the framework's implementation.  See the framework SDK
 * documentation for a class overview.
 */
public abstract class CursorAdapter extends BaseAdapter implements Filterable,
        CursorFilter.CursorFilterClient {
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected boolean mDataValid;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected boolean mAutoRequery;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected Cursor mCursor;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected Context mContext;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected int mRowIDColumn;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected ChangeObserver mChangeObserver;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected DataSetObserver mDataSetObserver;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected CursorFilter mCursorFilter;
    /**
     * This field should be made private, so it is hidden from the SDK.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    protected FilterQueryProvider mFilterQueryProvider;

    /**
     * If set the adapter will call requery() on the cursor whenever a content change
     * notification is delivered. Implies {@link #FLAG_REGISTER_CONTENT_OBSERVER}.
     *
     * @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 {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}.
     */
    @Deprecated
    public static final int FLAG_AUTO_REQUERY = 0x01;

    /**
     * If set the adapter will register a content observer on the cursor and will call
     * {@link #onContentChanged()} when a notification comes in.  Be careful when
     * using this flag: you will need to unset the current Cursor from the adapter
     * to avoid leaks due to its registered observers.  This flag is not needed
     * when using a CursorAdapter with a
     * {@link android.content.CursorLoader}.
     */
    public static final int FLAG_REGISTER_CONTENT_OBSERVER = 0x02;

    /**
     * Constructor that always enables auto-requery.
     *
     * @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 {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}.
     *
     * @param c The cursor from which to get the data.
     * @param context The context
     */
    @Deprecated
    public CursorAdapter(Context context, Cursor c) {
        init(context, c, FLAG_AUTO_REQUERY);
    }

    /**
     * Constructor that allows control over auto-requery.  It is recommended
     * you not use this, but instead {@link #CursorAdapter(Context, Cursor, int)}.
     * When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER}
     * will always be set.
     *
     * @param c The cursor from which to get the data.
     * @param context The context
     * @param autoRequery If true the adapter will call requery() on the
     *                    cursor whenever it changes so the most recent
     *                    data is always displayed.  Using true here is discouraged.
     */
    public CursorAdapter(Context context, Cursor c, boolean autoRequery) {
        init(context, c, autoRequery ? FLAG_AUTO_REQUERY : FLAG_REGISTER_CONTENT_OBSERVER);
    }

    /**
     * Recommended constructor.
     *
     * @param c The cursor from which to get the data.
     * @param context The context
     * @param flags Flags used to determine the behavior of the adapter; may
     * be any combination of {@link #FLAG_AUTO_REQUERY} and
     * {@link #FLAG_REGISTER_CONTENT_OBSERVER}.
     */
    public CursorAdapter(Context context, Cursor c, int flags) {
        init(context, c, flags);
    }

    /**
     * @deprecated Don't use this, use the normal constructor.  This will
     * be removed in the future.
     */
    @Deprecated
    protected void init(Context context, Cursor c, boolean autoRequery) {
        init(context, c, autoRequery ? FLAG_AUTO_REQUERY : FLAG_REGISTER_CONTENT_OBSERVER);
    }

    void init(Context context, Cursor c, int flags) {
        if ((flags & FLAG_AUTO_REQUERY) == FLAG_AUTO_REQUERY) {
            flags |= FLAG_REGISTER_CONTENT_OBSERVER;
            mAutoRequery = true;
        } else {
            mAutoRequery = false;
        }
        boolean cursorPresent = c != null;
        mCursor = c;
        mDataValid = cursorPresent;
        mContext = context;
        mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
        if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) {
            mChangeObserver = new ChangeObserver();
            mDataSetObserver = new MyDataSetObserver();
        } else {
            mChangeObserver = null;
            mDataSetObserver = null;
        }

        if (cursorPresent) {
            if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
            if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver);
        }
    }

    /**
     * Returns the cursor.
     * @return the cursor.
     */
    @Override
    public Cursor getCursor() {
        return mCursor;
    }

    /**
     * @see android.widget.ListAdapter#getCount()
     */
    @Override
    public int getCount() {
        if (mDataValid && mCursor != null) {
            return mCursor.getCount();
        } else {
            return 0;
        }
    }

    /**
     * @see android.widget.ListAdapter#getItem(int)
     */
    @Override
    public Object getItem(int position) {
        if (mDataValid && mCursor != null) {
            mCursor.moveToPosition(position);
            return mCursor;
        } else {
            return null;
        }
    }

    /**
     * @see android.widget.ListAdapter#getItemId(int)
     */
    @Override
    public long getItemId(int position) {
        if (mDataValid && mCursor != null) {
            if (mCursor.moveToPosition(position)) {
                return mCursor.getLong(mRowIDColumn);
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    /**
     * @see android.widget.ListAdapter#getView(int, View, ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (!mDataValid) {
            throw new IllegalStateException("this should only be called when the cursor is valid");
        }
        if (!mCursor.moveToPosition(position)) {
            throw new IllegalStateException("couldn't move cursor to position " + position);
        }
        View v;
        if (convertView == null) {
            v = newView(mContext, mCursor, parent);
        } else {
            v = convertView;
        }
        bindView(v, mContext, mCursor);
        return v;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        if (mDataValid) {
            mCursor.moveToPosition(position);
            View v;
            if (convertView == null) {
                v = newDropDownView(mContext, mCursor, parent);
            } else {
                v = convertView;
            }
            bindView(v, mContext, mCursor);
            return v;
        } else {
            return null;
        }
    }

    /**
     * Makes a new view to hold the data pointed to by cursor.
     * @param context Interface to application's global information
     * @param cursor The cursor from which to get the data. The cursor is already
     * moved to the correct position.
     * @param parent The parent to which the new view is attached to
     * @return the newly created view.
     */
    public abstract View newView(Context context, Cursor cursor, ViewGroup parent);

    /**
     * Makes a new drop down view to hold the data pointed to by cursor.
     * @param context Interface to application's global information
     * @param cursor The cursor from which to get the data. The cursor is already
     * moved to the correct position.
     * @param parent The parent to which the new view is attached to
     * @return the newly created view.
     */
    public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
        return newView(context, cursor, parent);
    }

    /**
     * Bind an existing view to the data pointed to by cursor
     * @param view Existing view, returned earlier by newView
     * @param context Interface to application's global information
     * @param cursor The cursor from which to get the data. The cursor is already
     * moved to the correct position.
     */
    public abstract void bindView(View view, Context context, Cursor cursor);

    /**
     * Change the underlying cursor to a new cursor. If there is an existing cursor it will be
     * closed.
     *
     * @param cursor The new cursor to be used
     */
    @Override
    public void changeCursor(Cursor cursor) {
        Cursor old = swapCursor(cursor);
        if (old != null) {
            old.close();
        }
    }

    /**
     * Swap in a new Cursor, returning the old Cursor.  Unlike
     * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
     * closed.
     *
     * @param newCursor The new cursor to be used.
     * @return Returns the previously set Cursor, or null if there was not one.
     * If the given new Cursor is the same instance is the previously set
     * Cursor, null is also returned.
     */
    public Cursor swapCursor(Cursor newCursor) {
        if (newCursor == mCursor) {
            return null;
        }
        Cursor oldCursor = mCursor;
        if (oldCursor != null) {
            if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
            if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
        }
        mCursor = newCursor;
        if (newCursor != null) {
            if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
            if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
            mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
            mDataValid = true;
            // notify the observers about the new cursor
            notifyDataSetChanged();
        } else {
            mRowIDColumn = -1;
            mDataValid = false;
            // notify the observers about the lack of a data set
            notifyDataSetInvalidated();
        }
        return oldCursor;
    }

    /**
     * <p>Converts the cursor into a CharSequence. Subclasses should override this
     * method to convert their results. The default implementation returns an
     * empty String for null values or the default String representation of
     * the value.</p>
     *
     * @param cursor the cursor to convert to a CharSequence
     * @return a CharSequence representing the value
     */
    @Override
    public CharSequence convertToString(Cursor cursor) {
        return cursor == null ? "" : cursor.toString();
    }

    /**
     * Runs a query with the specified constraint. This query is requested
     * by the filter attached to this adapter.
     *
     * The query is provided by a
     * {@link android.widget.FilterQueryProvider}.
     * If no provider is specified, the current cursor is not filtered and returned.
     *
     * After this method returns the resulting cursor is passed to {@link #changeCursor(Cursor)}
     * and the previous cursor is closed.
     *
     * This method is always executed on a background thread, not on the
     * application's main thread (or UI thread.)
     *
     * Contract: when constraint is null or empty, the original results,
     * prior to any filtering, must be returned.
     *
     * @param constraint the constraint with which the query must be filtered
     *
     * @return a Cursor representing the results of the new query
     *
     * @see #getFilter()
     * @see #getFilterQueryProvider()
     * @see #setFilterQueryProvider(android.widget.FilterQueryProvider)
     */
    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (mFilterQueryProvider != null) {
            return mFilterQueryProvider.runQuery(constraint);
        }

        return mCursor;
    }

    @Override
    public Filter getFilter() {
        if (mCursorFilter == null) {
            mCursorFilter = new CursorFilter(this);
        }
        return mCursorFilter;
    }

    /**
     * Returns the query filter provider used for filtering. When the
     * provider is null, no filtering occurs.
     *
     * @return the current filter query provider or null if it does not exist
     *
     * @see #setFilterQueryProvider(android.widget.FilterQueryProvider)
     * @see #runQueryOnBackgroundThread(CharSequence)
     */
    public FilterQueryProvider getFilterQueryProvider() {
        return mFilterQueryProvider;
    }

    /**
     * Sets the query filter provider used to filter the current Cursor.
     * The provider's
     * {@link android.widget.FilterQueryProvider#runQuery(CharSequence)}
     * method is invoked when filtering is requested by a client of
     * this adapter.
     *
     * @param filterQueryProvider the filter query provider or null to remove it
     *
     * @see #getFilterQueryProvider()
     * @see #runQueryOnBackgroundThread(CharSequence)
     */
    public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider) {
        mFilterQueryProvider = filterQueryProvider;
    }

    /**
     * Called when the {@link ContentObserver} on the cursor receives a change notification.
     * The default implementation provides the auto-requery logic, but may be overridden by
     * sub classes.
     *
     * @see ContentObserver#onChange(boolean)
     */
    protected void onContentChanged() {
        if (mAutoRequery && mCursor != null && !mCursor.isClosed()) {
            if (false) Log.v("Cursor", "Auto requerying " + mCursor + " due to update");
            mDataValid = mCursor.requery();
        }
    }

    private class ChangeObserver extends ContentObserver {
        ChangeObserver() {
            super(new Handler());
        }

        @Override
        public boolean deliverSelfNotifications() {
            return true;
        }

        @Override
        public void onChange(boolean selfChange) {
            onContentChanged();
        }
    }

    private class MyDataSetObserver extends DataSetObserver {
        MyDataSetObserver() {
        }

        @Override
        public void onChanged() {
            mDataValid = true;
            notifyDataSetChanged();
        }

        @Override
        public void onInvalidated() {
            mDataValid = false;
            notifyDataSetInvalidated();
        }
    }

}