ListView上的setEmptyView在Android应用程序中未显示其视图? [英] setEmptyView on ListView not showing its view in a android app?

查看:355
本文介绍了ListView上的setEmptyView在Android应用程序中未显示其视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ListView的setEmptyView方法有疑问.

I have a problem with the setEmptyView method from a ListView.

这是我的Java代码:

Here is my Java code:

ListView view = (ListView)findViewById(R.id.listView1);
view.setEmptyView(findViewById(R.layout.empty_list_item));

ArrayAdapter<Session> adapter1 = new ArrayAdapter<Session>(this, android.R.layout.simple_list_item_1, 
        android.R.id.text1, MainController.getInstanz().getItems());
view.setAdapter(adapter1);

empty_list_item:

empty_list_item:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/emptyList" >

</TextView>

列表视图:

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

我的代码有什么问题? 当我有项目时,我会在列表中看到它们.但是当列表为空时,我看不到TextView.

What is wrong with my code? When I have items I see them in the list. But when the list is empty I don't see the TextView.

推荐答案

问题是,我必须做一个addContentView:

the problem is, i have to do a addContentView:

View empty = getLayoutInflater().inflate(R.layout.empty_list_item, null, false);
addContentView(empty, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
view.setEmptyView(empty);

现在可以了

这篇关于ListView上的setEmptyView在Android应用程序中未显示其视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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