This is a really bizarre bug I am encountering.
If I run my code like this (adding a new item to my recyclerview), it works and updates fine:
mListOfData.add(someNewItem); mRecyclerViewAdapter = new RecyclerViewAdapter(this, mListOfData); mRecyclerViewAdapter.notifyDataSetChanged(); mRecyclerView.setAdapter(mRecyclerViewAdapter); But if I display a Snackbar telling the user an item has been added, suddenly the list doesn't update in real time unless I recreate the activity (rotating the screen, etc):
View view = findViewById(R.id.primary_coordinator_layout); mListOfData.add(someNewItem); mRecyclerViewAdapter = new RecyclerViewAdapter(this, mListOfData); mRecyclerViewAdapter.notifyDataSetChanged(); mRecyclerView.setAdapter(mRecyclerViewAdapter); Snackbar.make(view, "Item added!", Snackbar.LENGTH_SHORT).show(); Any reason why this may be or how to prevent it from blocking the visual update?
Here is the XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"/> <android.support.design.widget.CoordinatorLayout android:id="@+id/primary_coordinator_layout" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerview" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> <TextView android:id="@+id/emptytext" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:text="@string/no_items_in_recyclerview" android:layout_gravity="center_horizontal" android:gravity="center"/> </LinearLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_input_add"/> </android.support.design.widget.CoordinatorLayout> </LinearLayout>
No comments:
Post a Comment