這是我要做的事:
在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>
,並在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);
讓我知道,如果你需要更多信息。
感謝Viswesh和Ishata,我遵循指示和工作。 –
很高興幫助。 :) –
您需要觀察適配器中的數據集。如果數據集爲空,則只顯示空白視圖。如果項目被動態移除,此解決方案將不起作用。 – Pawan