为什么在布局文件空查看屏幕上显示的,即使列表视图有项目?视图、布局、文件、项目

2023-09-12 05:26:59 作者:‐ Mind 为你安分守己

我有一个ListView显示一些项目,我也用的情况下,我的适配器的列表视图来show.Problem没有项目的空观点是,当我去这个这个活动首先,它显示在屏幕上的一个空的观点第二个,然后加载项,并显示在列表视图。

I have a Listview to show some item and i have also used an empty view in case my adapter has no item for listview to show.Problem is when I go this this activity first it shows the empty view on the screen for a second and then loads the item and show them in listview.

我的动态的onCreate 是这样的:

@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 is:

<?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>

我该怎么办确保空的观点一直没有出现,即使是第二,如果我们有我们的adapter.Should数据我检查适配器后附加的空视图列出后或THR任何其他方式做到这一点?

How I Do make sure that empty view never shows up even for a second if we have data in our adapter.Should I attach the empty view to list later after checking the adapter or is thr any other way to do this?

推荐答案

我找到了答案。我只需要申请空视图 list.setEmptyView(空)在我的设置我的适配器列表,并将其完美的作品后的AsyncTask onPostExecute()方法。

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