For some reason, when adding a new item to the RecyclerView (should be inserted to the top of the list), it won't show up unless I scroll down the list and back up to the top, and without any animation either. (Just appears at the top of the list as if it was there the whole time). Removing an item works fine with the proper animations.
RecyclerViewAdapter:
@Override
public void onNewDatabaseEntryAdded() {
//item added to top of the list
notifyItemInserted(0);
}
public FileViewerAdapter(Context context) {
super();
mContext = context;
mDatabase = new DBHelper(mContext);
mDatabase.setOnDatabaseChangedListener(this);
}
SQLite Database:
private static OnDatabaseChangedListener mOnDatabaseChangedListener;
public static void setOnDatabaseChangedListener(OnDatabaseChangedListener listener) {
mOnDatabaseChangedListener = listener;
}
public long addRecording(String recordingName, String filePath, long length) {
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(DBHelperItem.COLUMN_NAME_RECORDING_NAME, recordingName);
cv.put(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH, filePath);
cv.put(DBHelperItem.COLUMN_NAME_RECORDING_LENGTH, length);
cv.put(DBHelperItem.COLUMN_NAME_TIME_ADDED, System.currentTimeMillis());
long rowId = db.insert(DBHelperItem.TABLE_NAME, null, cv);
if (mOnDatabaseChangedListener != null) {
mOnDatabaseChangedListener.onNewDatabaseEntryAdded();
}
return rowId;
}
Listener:
public interface OnDatabaseChangedListener{
void onNewDatabaseEntryAdded();
void onDatabaseEntryRenamed();
}
edit:
I should mention that if I use NotifyDataSetChanged instead of NotifyItemInserted, then the new item shows up immediately, but the RecyclerView will not scroll to the top of the list. (Manually have to scroll up to see it).