Android中CursorAdapter的使用详解

/*** 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*/public void changeCursor (Cursor cursor) {Cursor old = swapCursor(cursor);if (old != null) {old.close();}} swapCursor(cusor)的源码如下:/*** 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 wasa 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 cursornotifyDataSetChanged();} else {mRowIDColumn = -1;mDataValid = false;// notify the observers about the lack of a data setnotifyDataSetInvalidated();}return oldCursor;}

,偶尔也要现实和虚伪一点,因为不那样做的话,很难混。

Android中CursorAdapter的使用详解

相关文章:

你感兴趣的文章:

标签云: