为什么在布局文件空查看屏幕上显示的,即使列表视图有项目? [英] Why does empty view in layout file shows up on screen even though listview has items?

查看:103
本文介绍了为什么在布局文件空查看屏幕上显示的,即使列表视图有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

这篇关于为什么在布局文件空查看屏幕上显示的,即使列表视图有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆