You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The number of headers to be displayed by default if child classes want a header
publicstaticfinalintHEADER_COUNT = 1;
//The number of footers to be displated by default if child classes want a footer
publicstaticfinalintFOOTER_COUNT = 1;
//A listener that is triggered when items are added or removed to the Recycler View.
protectedOnChangedListener<U> onChangedListener;
privateViewmEmptyView;
//The Cursor object that will contain all the rows that you want to display inside the Recycler View
privateCursormCursor;
//A variable indicating if the data contained in the Cursor above is valid
privatebooleanmDataValid;
privatebooleanisValid;
//The index of the column containing _id of an SQLite database table from which you want to load data inside the Cursor above
privateintindexColumnId;
//the index of the column containing _id of an SQLite database table from which you want to load data inside the Cursor above
privateintmIndexColumnId;
publicRecyclerCursorAdapter(Contextcontext) {
this.context = context;
this.headers = newArrayList<>();
this.footers = newArrayList<>();
publicCursorgetCursor() {
returnmCursor;
}
/**
* Check if the data contained by the cursor is valid and try to extract the value of the column index _id
* To indicate that your RecyclerView needs to refresh what it displays, call notifyDataSetChanged
*
* @param cursor the rows from a database table that you want to display inside your RecyclerView
* @param onChangedListener A class that wishes to get notified when items are added or removed from the Recycler View. When items are added, subclasses must take responsibility of controlling when to fire the 'onAdd' event and when items are swiped to the right in an LTR environment or to the left in an RTL environment, the 'onRemove' event is fired.
* If you are setting the cursor for the first time, create it from scratch, else swap it or change it.
* If the data source is set for the first time, create a Cursor object from scratch else swap the existing Cursor object with a new cursor object. Depending on whether the Cursor has any rows at all, update the empty view if set.
*
* @param cursor containing the rows from your SQLite table that you want to display inside your RecyclerView
*/
publicvoidsetCursor(Cursorcursor) {
publicvoidsetDataSource(Cursorcursor) {
if (mCursor == null) {
createCursor(cursor);
} else {
changeCursor(cursor);
swapCursor(cursor);
}
toggleEmptyView();
}
/**
* Change the underlying cursor to a new cursor. If there is an existing cursor it will be
* closed.
* Check if the data contained by the mCursor is valid and try to extract the value of the column index _id
* To indicate that your RecyclerView needs to refresh what it displays, call notifyDataSetChanged
*
* @param cursor the rows from a database table that you want to display inside your RecyclerView
* If the new and old cursor are same, do nothing, otherwise store the old and new cursors respectively. If the new cursor is not null, notify that data has changed and mark data as valid
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
* closed.
* Change the underlying mCursor to a new mCursor. If there is an existing mCursor it will be
* closed. If the new and old mCursor are same, do nothing, otherwise store the old and new cursors respectively. If the new mCursor is not null, notify that data has changed and mark data as valid. Swap in a new Cursor, returning the old Cursor. Unlike {@link #swapCursor(Cursor)}, the returned old Cursor is <em>not</em> closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* If you are setting the cursor for the first time, create it from scratch, else swap it or change it.
*
* @param cursor containing the rows from your SQLite table that you want to display inside your RecyclerView
*/
publicvoidsetCursor(Cursorcursor) {
if (mCursor == null) {
createCursor(cursor);
} else {
changeCursor(cursor);
}
}
/**
* Change the underlying cursor to a new cursor. If there is an existing cursor it will be
* closed.
*/
publicvoidchangeCursor(Cursorcursor) {
Cursorold = swapCursor(cursor);
if (old != null) {
old.close();
}
}
/**
* If the new and old cursor are same, do nothing, otherwise store the old and new cursors respectively. If the new cursor is not null, notify that data has changed and mark data as valid
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
* @param position of the current item within the RecyclerView whose item id we need to specify.
* @return the index of the column _id from the SQLite database table whose rows you are trying to display inside the RecyclerView, 0 if you dont have valid data in your Cursor
*/
@Override
publiclonggetItemId(intposition) {
if (mDataValid && mCursor != null && mCursor.moveToPosition(position)) {