ListView控件显示简要之前的数据装入空消息 [英] ListView shows empty message briefly before data is loaded

查看:151
本文介绍了ListView控件显示简要之前的数据装入空消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的自定义布局添加了创建 ListFragment A 的TextView 来显示一个消息时,列表是空的:

I've created a ListFragment using the following custom layout which adds a TextView to show a message when the list is empty:

<?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/android:list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:drawSelectorOnTop="false"/>

  <TextView android:id="@id/android:empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/vsl_empty"
            android:gravity="center"
            android:layout_gravity="center"
            android:textColor="#8C8C8C" />
</LinearLayout>

中的数据是使用源自的CursorAdapter 自定义适配器加载。当在数据库中的数据,列表非常短暂地显示,直到数据被装载空列表消息,在该点列表被填充。

The data is loaded using a custom adapter that derives from CursorAdapter. When there is data in the database, the list very briefly shows the empty list message until the data is loaded, at which point the list gets populated.

我怎样才能prevent从短暂出现,因为该名单还没有被填充但空列表消息?

How can I prevent the empty list message from briefly appearing because the list hasn't been populated yet?

更新

我要强调的是,我使用了一个 ListFragment 使用包含布局的的ListView 的特殊ID 安卓列表的TextView 的特殊ID Android版本:空,因为这里解释

I want to emphasise that I'm using a ListFragment with a layout that contains a ListView with the special id android:list, and a TextView with the special id android:empty, as explained here.

设置安卓知名度=隐形不影响能见度。我怀疑这是因为它被设置为可见的内部。

Setting android:visibility="invisible" doesn't affect the visibility. I suspect this is because it gets set to visible internally.

推荐答案

提供的答案是在正确的轨道。我确实有设置的TextView 为不可见,但正确的位置是在 onCreateLoader

The provided answers were on the right track. I indeed had to set the TextView to invisible, but the correct location is in onCreateLoader:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
  mListView.getEmptyView().setVisibility(ListView.GONE);

  return new CursorLoader(getActivity(), CONTENT_URI, null, null, null, null);
}

此外,它没有必要使空的观点再次可见:这是由框架自动完成

Also, it's not necessary to make the empty view visible again: this is done automatically by the framework.

这篇关于ListView控件显示简要之前的数据装入空消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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