0

Bu gerçekten karşılaştığım çok tuhaf bir böcek.Snackbar, Recyclerview'ın görünümünü güncellemesini engelliyor mu?

böyle kodumu (benim recyclerview yeni bir öğe ekleyerek) çalıştırırsanız, nasıl çalıştığını ve güncellemeler ince:

mListOfData.add(someNewItem); 
mRecyclerViewAdapter = new RecyclerViewAdapter(this, mListOfData); 
mRecyclerViewAdapter.notifyDataSetChanged(); 
mRecyclerView.setAdapter(mRecyclerViewAdapter); 

Ama Snackbar aniden bir öğe eklendi kullanıcıyı söylüyorum görüntülüyorlarsa Ben aktiviteyi (ekran döndürme, vs) yeniden sürece liste gerçek zamanlı olarak güncellenir değildir:

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(); 

bu olabilir ya da ne kadar görsel güncelleştirme engellemesini önlemek için bir nedeni?

<?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> 

cevap

1

deneyin görevden snackbar sonra: İşte

XML

final RecyclerViewAdapter mRecyclerViewAdapter2 = new RecyclerViewAdapter(this, mListOfData); 


//create local snackbar 
final Snackbar snackBar = Snackbar.make(view, "Item added!", Snackbar.LENGTH_SHORT); 

snackBar.setAction("Blah blah", new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     mRecyclerView.setAdapter(mRecyclerViewAdapter2); 
     mRecyclerViewAdapter2.notifyDataSetChanged(); 
     snackBar.dismiss(); 
    } 
}); 
snackBar.show(); 
+0

Aynı sorun maalesef –

+0

güncellenen cevabı deneyebilir miyim? –

+0

Bunun nedenini öğrendim, Snackbar ile ilgili bir şey yapmadım (boşluğun doğru görünmemesi ile ilgili bir şeyler yapmak zorunda kaldım), ama zaman ve çaba için bir onay işareti/vereceğim –

İlgili konular