I am trying to get item animations working on my RecyclerView. The animations are meant to be using the standard DefaultItemAnimator, and the RecyclerView is showing a run-of-the-mill list of CardViews. Unfortunately I have been unable to get the animations to show at all. My code is included below, but without errors in logcat, it is hard for me to pinpoint the origin of the fault. Please ask for more info if needed.
In my fragment I have:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_main, container, false);
mRecyclerView = (RecyclerView)layout.findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mRVLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mRVLayoutManager);
// the cursor is successfully swapped into the adapter when the loader does it's job
mCursorAdapter = new RationCursorAdapter( null );
mRecyclerView.setAdapter(mCursorAdapter);
/////////
// this should work right?!
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
/////////
return layout;
}
The RecyclerView displays the list as intended, and as far as I can tell is running smoothly and properly, but just the animations never show.
Items are added via the ContentProvider
ContentResolver resolver = getContentResolver();
resolver.insert(DataContract.Entry.CONTENT_URI, content_values);
which looks like this:
@Override
public Uri insert(Uri uri, ContentValues values) {
if( uriMatcher.match(uri) == ENTRY_URI ){
SQLiteDatabase DB = dbHelper.getWritableDatabase();
long id = DB.insert(
DataContract.Entry.TABLE_NAME,
null,
values
);
if(id != -1 ){
// successfully inserted
getContext().getContentResolver().notifyChange( uri, null );
return DataContract.Entry.buildEntryUri(id);
}
// problem inserting
throw new SQLException("Error inserting into database with URI " + uri);
}
throw new IllegalArgumentException("Inserting is not supported with URI " + uri);
}
I am running all this on a Nexus phone running Android 5.1
Any ideas on how to get this working? Thanks.
Aucun commentaire:
Enregistrer un commentaire