Why is a blank screen in the layout file displayed on the screen even if there are items in the list?

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) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.favorite_exams); list = (ListView) findViewById(R.id.favoriteExamsList); View empty = findViewById(R.id.favoriteExamsListEmptyView); list.setEmptyView(empty); new readingFavFileTask().execute(UtilityFuctions.FAV_EXAMS_FILE_NAME); } 

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?

+4
source share
1 answer

I have found the answer. I just need to apply Empty View list.setEmptyView(empty) in my AsyncTask onPostExecute () method after setting my adapter to the list, and it works fine.

+5
source

Source: https://habr.com/ru/post/1440772/


All Articles