安卓:设置空视图列表视图 [英] Android: set empty view to a list view

查看:154
本文介绍了安卓:设置空视图列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <TextView
            android:id="@android:id/empty"
            style="@style/FacebookFont"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/no_result_found"
            android:textColor="@color/white" />

这是XML code为空视图。我设置空的观点如下:

this is the xml code for empty view. I am setting empty view as follows:

    list.setAdapter(adapter);
    list.setEmptyView(findViewById(android.R.id.empty));

我在列表视图中的项目即使这样的ListView填充显示空的观点也之前。 我不希望被证明为空视图时,列表视图中包含的一些项目。

I have the items in the listview even then also before listview is populated the empty view is shown. I don't want that empty view to be shown when listview contains some item.

请帮忙。

推荐答案

。删除 list.setEmptyView(findViewById(android.R.id.empty)); 从code

更改您的布局像下面那么它的自动添加 EmptyView 如果列表中没有的项目:

Change your layout like below then it's automatically add EmptyView if list has no item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="8dp"
        android:paddingRight="8dp">

    <ListView android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00FF00"
            android:layout_weight="1"
            android:drawSelectorOnTop="false"/>

     <TextView android:id="@android:id/empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0000"
            android:text="No data"/>

</LinearLayout>

这篇关于安卓:设置空视图列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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