If notifyDataSetChanged()
does not trigger view updates than there is a chance that you have forgotten to call SetLayoutManager()
on your RecyclerView (like I did!).
Just don't forget to do this:
Java code:
LinearLayoutManager layoutManager = new LinearLayoutManager(context ,LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager)
C# code, I'm using Xamarin.
var layoutManager = new LinearLayoutManager(Context, LinearLayoutManager.Vertical, false);
recyclerView.SetLayoutManager(layoutManager);
before you call recyclerView.SetAdapter(adapter)
;
If you prefer declaring it in xml, so you cannot forget it in the code you can also add these lines to the xml of your recyclerView:
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…