I have a Listview to show some element, and I also used an empty view if my adapter does not have an element to display the list. The problem is that when I start this operation first, it shows a blank view on the screen for then load the item and show them in the list.
My onCreate activity is as follows:
@Override protected void onCreate(Bundle savedInstanceState) {
My layout file:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/favoriteExamsList" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> <LinearLayout android:id="@+id/favoriteExamsListEmptyView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:visibility="gone" > <TextView android:id="@+id/favoriteExamsEmptyViewMessage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="You do not have any favorite Exams.Please add Exams using below button." android:textSize="20dp" /> <Button android:id="@+id/favoriteExamsAdd" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:onClick="onClickAddExams" android:text="Add Exams" > </Button> </LinearLayout> </LinearLayout>
As I do, make sure that the empty view never appears even for a second if we have data in our adapter. Should I add an empty list to the list later after checking the adapter or in some other way do it?
source share