Add an option to not register the ContentObserver when creating a CursorAdapter.
Change-Id: Ic18f0307f5ba0d54f7270d8d1e032feff537360b
This commit is contained in:
@@ -200039,6 +200039,20 @@
|
||||
<parameter name="autoRequery" type="boolean">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<constructor name="CursorAdapter"
|
||||
type="android.widget.CursorAdapter"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="c" type="android.database.Cursor">
|
||||
</parameter>
|
||||
<parameter name="flags" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<method name="bindView"
|
||||
return="void"
|
||||
abstract="true"
|
||||
@@ -200186,6 +200200,23 @@
|
||||
<parameter name="autoRequery" type="boolean">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="init"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="protected"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="c" type="android.database.Cursor">
|
||||
</parameter>
|
||||
<parameter name="flags" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="newDropDownView"
|
||||
return="android.view.View"
|
||||
abstract="false"
|
||||
@@ -200257,6 +200288,28 @@
|
||||
<parameter name="filterQueryProvider" type="android.widget.FilterQueryProvider">
|
||||
</parameter>
|
||||
</method>
|
||||
<field name="FLAG_AUTO_REQUERY"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="FLAG_REGISTER_CONTENT_OBSERVER"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="2"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<class name="CursorTreeAdapter"
|
||||
extends="android.widget.BaseExpandableListAdapter"
|
||||
|
||||
@@ -79,6 +79,18 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static final int FLAG_REGISTER_CONTENT_OBSERVER = 0x02;
|
||||
|
||||
/**
|
||||
* Constructor. The adapter will call requery() on the cursor whenever
|
||||
* it changes so that the most recent data is always displayed.
|
||||
@@ -87,7 +99,7 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
|
||||
* @param context The context
|
||||
*/
|
||||
public CursorAdapter(Context context, Cursor c) {
|
||||
init(context, c, true);
|
||||
init(context, c, FLAG_AUTO_REQUERY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,19 +111,43 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
|
||||
* data is always displayed.
|
||||
*/
|
||||
public CursorAdapter(Context context, Cursor c, boolean autoRequery) {
|
||||
init(context, c, autoRequery);
|
||||
init(context, c, autoRequery ? FLAG_AUTO_REQUERY : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public CursorAdapter(Context context, Cursor c, int flags) {
|
||||
init(context, c, flags);
|
||||
}
|
||||
|
||||
protected void init(Context context, Cursor c, boolean autoRequery) {
|
||||
init(context, c, autoRequery ? FLAG_AUTO_REQUERY : 0);
|
||||
}
|
||||
|
||||
protected 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;
|
||||
mAutoRequery = autoRequery;
|
||||
mCursor = c;
|
||||
mDataValid = cursorPresent;
|
||||
mContext = context;
|
||||
mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
|
||||
mChangeObserver = new ChangeObserver();
|
||||
if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) {
|
||||
mChangeObserver = new ChangeObserver();
|
||||
} else {
|
||||
mChangeObserver = null;
|
||||
}
|
||||
|
||||
if (cursorPresent) {
|
||||
c.registerContentObserver(mChangeObserver);
|
||||
if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
|
||||
c.registerDataSetObserver(mDataSetObserver);
|
||||
}
|
||||
}
|
||||
@@ -246,13 +282,13 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
|
||||
return;
|
||||
}
|
||||
if (mCursor != null) {
|
||||
mCursor.unregisterContentObserver(mChangeObserver);
|
||||
if (mChangeObserver != null) mCursor.unregisterContentObserver(mChangeObserver);
|
||||
mCursor.unregisterDataSetObserver(mDataSetObserver);
|
||||
mCursor.close();
|
||||
}
|
||||
mCursor = cursor;
|
||||
if (cursor != null) {
|
||||
cursor.registerContentObserver(mChangeObserver);
|
||||
if (mChangeObserver != null) cursor.registerContentObserver(mChangeObserver);
|
||||
cursor.registerDataSetObserver(mDataSetObserver);
|
||||
mRowIDColumn = cursor.getColumnIndexOrThrow("_id");
|
||||
mDataValid = true;
|
||||
|
||||
Reference in New Issue
Block a user