Dies ist, wie ich es tun:
In XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/empty_text"
android:textAppearance="?android:textAppearanceMedium"
android:visibility="invisible" />
<android.support.v7.widget.RecyclerView
android:id="@+id/education_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layoutManager="LinearLayoutManager" />
</FrameLayout>
und im Activity
:
if (!data.isEmpty()) {
//if data is available, don't show the empty text
emptyText.setVisibility(View.INVISIBLE);
RecyclerAdapter adapter = new RecyclerAdapter(data); // pass the data to your adapter here
recyclerView.setAdapter(adapter);
} else
emptyText.setVisibility(View.VISIBLE);
Lassen Sie mich wissen, wenn Sie brauche weitere Informationen.
Danke Viswesh und Ishata, ich folge den Anweisungen und ihrer Arbeit. –
Froh, zu helfen. :) –
Sie müssen das Dataset in einem Adapter beobachten. Wenn das Dataset leer ist, zeigen Sie nur eine leere Ansicht an. Diese Lösung funktioniert nicht, wenn die Elemente dynamisch entfernt werden. – Pawan