Implementation
String
Message in the string.xml file to give a feedback
<string name="empty_list">No Information Available</string>
<string name="empty_list_no_network">No information available. The network is not available to fetch data.</string>
<string name="empty_list_server_down">No information available. The server is not returning data.</string>
<string name="empty_list_server_error">No information available. The server is not returning valid data. Please check for an updated version of Sunshine.</string>
<string name="empty_list_invalid_parameter">No information available. The parameter in settings is not recognized by the server.</string>
Layout file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.myapp.myFragment">
<ListView
android:id="@+id/listview"
/>
<!-- empty list -->
<TextView
android:id="@+id/listview_empty"
android:text="@string/empty_list"
/>
</FrameLayout>
Activity / Fragment
In the onCreateView method
// Set the empty view for the list View
ListView mListView = (ListView) rootView.findViewById(R.id.listview);
TextView emptyView = (TextView) rootView.findViewById(R.id.listview_empty);
mListView.setEmptyView(emptyView);
// Message
int message = R.string.empty_list_no_network;
emptyView.setText(message);