Methods Summary |
---|
public synchronized void | close()
if (mContentObserver != null) {
mCursor.unregisterContentObserver(mContentObserver);
mContentObserver = null;
}
mCursor.close();
mCursor = null;
|
protected void | finalize()
if (mCursor != null) close();
super.finalize();
|
public synchronized java.util.Map | getRows()
if (mDirty) requery();
return mValues;
|
public synchronized ContentValues | getValues(java.lang.String rowName)Access the ContentValues for the row specified by rowName
if (mDirty) requery();
return mValues.get(rowName);
|
private synchronized void | readCursorIntoCache()
// Make a new map so old values returned by getRows() are undisturbed.
int capacity = mValues != null ? mValues.size() : 0;
mValues = new HashMap<String, ContentValues>(capacity);
while (mCursor.moveToNext()) {
ContentValues values = new ContentValues();
for (int i = 0; i < mColumnNames.length; i++) {
if (i != mKeyColumn) {
values.put(mColumnNames[i], mCursor.getString(i));
}
}
mValues.put(mCursor.getString(mKeyColumn), values);
}
|
public void | requery()Requeries the cursor and reads the contents into the cache
mDirty = false;
mCursor.requery();
readCursorIntoCache();
setChanged();
notifyObservers();
|
public void | setKeepUpdated(boolean keepUpdated)Change whether or not the ContentQueryMap will register with the cursor's ContentProvider
for change notifications. If you use a ContentQueryMap in an activity you should call this
with false in onPause(), which means you need to call it with true in onResume()
if want it to be kept updated.
if (keepUpdated == mKeepUpdated) return;
mKeepUpdated = keepUpdated;
if (!mKeepUpdated) {
mCursor.unregisterContentObserver(mContentObserver);
mContentObserver = null;
} else {
if (mHandlerForUpdateNotifications == null) {
mHandlerForUpdateNotifications = new Handler();
}
if (mContentObserver == null) {
mContentObserver = new ContentObserver(mHandlerForUpdateNotifications) {
@Override
public void onChange(boolean selfChange) {
// If anyone is listening, we need to do this now to broadcast
// to the observers. Otherwise, we'll just set mDirty and
// let it query lazily when they ask for the values.
if (countObservers() != 0) {
requery();
} else {
mDirty = true;
}
}
};
}
mCursor.registerContentObserver(mContentObserver);
// mark dirty, since it is possible the cursor's backing data had changed before we
// registered for changes
mDirty = true;
}
|