Java Code Examples for android.database.Cursor#unregisterDataSetObserver()
The following examples show how to use
android.database.Cursor#unregisterDataSetObserver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CursorAdapter.java From guideshow with MIT License | 6 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }
Example 2
Source File: CursorAdapter.java From watchlist with Apache License 2.0 | 6 votes |
public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } final Cursor oldCursor = mCursor; if (oldCursor != null && mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (mCursor != null) { if (mDataSetObserver != null) { mCursor.registerDataSetObserver(mDataSetObserver); } rowIdColumn = newCursor.getColumnIndexOrThrow("_id"); dataIsValid = true; notifyDataSetChanged(); } else { rowIdColumn = -1; dataIsValid = false; notifyDataSetChanged(); } return oldCursor; }
Example 3
Source File: CursorRecyclerViewAdapter.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
public Cursor swapCursor(Cursor newCursor) { if (newCursor == cursor) { return null; } final Cursor oldCursor = cursor; if (oldCursor != null) { oldCursor.unregisterDataSetObserver(observer); } cursor = newCursor; if (cursor != null) { cursor.registerDataSetObserver(observer); } valid = cursor != null; notifyDataSetChanged(); return oldCursor; }
Example 4
Source File: CursorRecyclerViewAdapter.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } final Cursor oldCursor = mCursor; if (oldCursor != null && mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (mCursor != null) { if (mDataSetObserver != null) { mCursor.registerDataSetObserver(mDataSetObserver); } mRowIdColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; notifyDataSetChanged(); } else { mRowIdColumn = -1; mDataValid = false; notifyDataSetChanged(); //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter } return oldCursor; }
Example 5
Source File: CursorRecyclerViewAdapter.java From homeassist with Apache License 2.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } final Cursor oldCursor = mCursor; if (oldCursor != null && mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (mCursor != null) { if (mDataSetObserver != null) { mCursor.registerDataSetObserver(mDataSetObserver); } mRowIdColumn = newCursor.getColumnIndexOrThrow(getIdColName()); mDataValid = true; notifyDataSetChanged(); } else { mRowIdColumn = -1; mDataValid = false; notifyDataSetChanged(); //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter } return oldCursor; }
Example 6
Source File: MergeCursor.java From libcommon with Apache License 2.0 | 6 votes |
/** * 指定したインデックスが示す位置に指定したCursorをセットする * 保持しているCursorの数がインデックスより少ない場合は空いている箇所にnullがセットされる * @param index * @param cursor * @return */ @Nullable public Cursor add(final int index, @NonNull final Cursor cursor) { synchronized (mCursors) { if (mCursors.size() <= index) { mCursors.ensureCapacity(index + 1); for (int i = mCursors.size(); i <= index; i++) { mCursors.add(null); } } final Cursor oldCursor = getCursor(index); mCursors.add(index, cursor); cursor.registerDataSetObserver(mObserver); if (oldCursor != null) { oldCursor.unregisterDataSetObserver(mObserver); } return oldCursor; } }
Example 7
Source File: TableOfContentRecyclerViewAdapter.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. */ @Nullable public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } final Cursor oldCursor = mCursor; if (oldCursor != null && mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (mCursor != null) { if (mDataSetObserver != null) { mCursor.registerDataSetObserver(mDataSetObserver); } mDataValid = true; notifyDataSetChanged(); } else { mRowIdColumn = -1; mDataValid = false; notifyDataSetChanged(); //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter } return oldCursor; }
Example 8
Source File: CursorRecyclerViewAdapter.java From GoogleFitExample with Apache License 2.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } final Cursor oldCursor = mCursor; if (oldCursor != null && mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (mCursor != null) { if (mDataSetObserver != null) { mCursor.registerDataSetObserver(mDataSetObserver); } mRowIdColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; notifyDataSetChanged(); } else { mRowIdColumn = -1; mDataValid = false; notifyDataSetChanged(); //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter } return oldCursor; }
Example 9
Source File: MergeCursor.java From libcommon with Apache License 2.0 | 5 votes |
/** * 指定したCursorを削除する * @param cursor */ public void remove(@NonNull final Cursor cursor) { synchronized (mCursors) { cursor.unregisterDataSetObserver(mObserver); mCursors.remove(cursor); } }
Example 10
Source File: CursorRecyclerAdapter.java From Ouroboros with GNU General Public License v3.0 | 5 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set // notifyDataSetInvalidated(); notifyItemRangeRemoved(0, getItemCount()); } return oldCursor; }
Example 11
Source File: MergeCursor.java From libcommon with Apache License 2.0 | 5 votes |
@Override public void unregisterDataSetObserver(final DataSetObserver observer) { mObserver = mDefaultObserver; synchronized (mCursors) { for (final Cursor cursor: mCursors) { if (cursor != null) { cursor.unregisterDataSetObserver(observer); } } } }
Example 12
Source File: RecyclerViewCursorAdapter.java From BLEMeshChat with Mozilla Public License 2.0 | 5 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); // notifyDataSetInvalidated(); } return oldCursor; }
Example 13
Source File: CursorRecyclerAdapter.java From yahnac with Apache License 2.0 | 5 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set // notifyDataSetInvalidated(); notifyItemRangeRemoved(0, getItemCount()); } return oldCursor; }
Example 14
Source File: RecyclerViewCursorBaseAdapter.java From HightCopyWX with Apache License 2.0 | 5 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set // notifyDataSetInvalidated(); //there is no notifyDataSetInvalidated method we should use notifyDataSetChanged method; notifyDataSetChanged(); } return oldCursor; }
Example 15
Source File: CursorPagerAdapter.java From android-open-project-demo with Apache License 2.0 | 5 votes |
/** * 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 notifyDataSetChanged(); } return oldCursor; }
Example 16
Source File: CursorAdapter.java From letv with Apache License 2.0 | 5 votes |
public Cursor swapCursor(Cursor newCursor) { if (newCursor == this.mCursor) { return null; } Cursor oldCursor = this.mCursor; if (oldCursor != null) { if (this.mChangeObserver != null) { oldCursor.unregisterContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(this.mDataSetObserver); } } this.mCursor = newCursor; if (newCursor != null) { if (this.mChangeObserver != null) { newCursor.registerContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { newCursor.registerDataSetObserver(this.mDataSetObserver); } this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); this.mDataValid = true; notifyDataSetChanged(); return oldCursor; } this.mRowIDColumn = -1; this.mDataValid = false; notifyDataSetInvalidated(); return oldCursor; }
Example 17
Source File: CursorAdapter.java From letv with Apache License 2.0 | 5 votes |
public Cursor swapCursor(Cursor newCursor) { if (newCursor == this.mCursor) { return null; } Cursor oldCursor = this.mCursor; if (oldCursor != null) { if (this.mChangeObserver != null) { oldCursor.unregisterContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(this.mDataSetObserver); } } this.mCursor = newCursor; if (newCursor != null) { if (this.mChangeObserver != null) { newCursor.registerContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { newCursor.registerDataSetObserver(this.mDataSetObserver); } this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); this.mDataValid = true; notifyDataSetChanged(); return oldCursor; } this.mRowIDColumn = -1; this.mDataValid = false; notifyDataSetInvalidated(); return oldCursor; }
Example 18
Source File: CursorRecyclerAdapter.java From android-atleap with Apache License 2.0 | 5 votes |
/** * 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 cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); //notifyDataSetInvalidated(); } return oldCursor; }
Example 19
Source File: MediaStoreCursorRecyclerAdapter.java From libcommon with Apache License 2.0 | 5 votes |
/** * カーソルを交換 * @param newCursor * @return */ @Nullable protected Cursor swapCursor(@Nullable final Cursor newCursor) { if (DEBUG) Log.v(TAG, "swapCursor:" + newCursor); if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) { oldCursor.unregisterContentObserver(mChangeObserver); } if (mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } } synchronized (mSync) { mCursor = newCursor; } if (newCursor != null) { if (mChangeObserver != null) { newCursor.registerContentObserver(mChangeObserver); } if (mDataSetObserver != null) { newCursor.registerDataSetObserver(mDataSetObserver); } mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }
Example 20
Source File: GameAdapter.java From citra_android with GNU General Public License v3.0 | 5 votes |
/** * When a load is finished, call this to replace the existing data with the newly-loaded * data. * * @param cursor The newly-loaded Cursor. */ public void swapCursor(Cursor cursor) { // Sanity check. if (cursor == mCursor) { return; } // Before getting rid of the old cursor, disassociate it from the Observer. final Cursor oldCursor = mCursor; if (oldCursor != null && mObserver != null) { oldCursor.unregisterDataSetObserver(mObserver); } mCursor = cursor; if (mCursor != null) { // Attempt to associate the new Cursor with the Observer. if (mObserver != null) { mCursor.registerDataSetObserver(mObserver); } mDatasetValid = true; } else { mDatasetValid = false; } notifyDataSetChanged(); }