使用setEmptyView在ListActivity问题 [英] Problem using setEmptyView on a ListActivity

查看:93
本文介绍了使用setEmptyView在ListActivity问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的设置,而空观点的文字显示不出来...

I have the following setup, and the empty view text doesn't show up...

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            getListView().setEmptyView(findViewById(R.id.empty));
    getListView().setTextFilterEnabled(true);

    setListAdapter(null);// to have empty list
}

布局文件是:

The layout file is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/myScrollLayout"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
    <FrameLayout android:layout_width="fill_parent"
        android:layout_height="0dip" android:layout_weight="1">
        <ListView android:id="@android:id/list" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:drawSelectorOnTop="false" />

        <!-- Here is the view to show if the list is emtpy -->
        <ScrollView
            android:id="@android:id/empty" android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView android:id="@+id/emptyText" android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:text="@string/contact_empty_help"
                android:textSize="20sp" android:textColor="?android:attr/textColorSecondary"
                android:paddingLeft="10dip" android:paddingRight="10dip"
                android:paddingTop="10dip" android:lineSpacingMultiplier="0.92" />
        </ScrollView>
    </FrameLayout>
</LinearLayout>

字符串的定义是:

String is defined as:

<string name="contact_empty_help">"You don't have any contacts to display.\n\nTo add contacts, you have to:\n
        \n<li><font fgcolor="#ffffffff">Go to <b>Contacts</b></font> application to create new contacts\n</li>
        \n<li><font fgcolor="#ffffffff"><b>Import from VCF file</b></font>, this is available in Contacts menu, the file most be on the root of the SD card\n</li>"
        </string>

由于列表是空的,就应该告诉我定义的文本。我跟着从List8

Since the list is empty, it should show me the text defined. I followed the example from the List8

<一个href="http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List8.html" rel="nofollow">http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List8.html
http://developer.android.com/intl/de/resources/samples/ApiDemos/res/layout/list_8.xml

推荐答案

我是缺少一个的setContentView(R.layout.listview);而这个视图,因为是不挑调升通过findViewById。

I was missing a setContentView(R.layout.listview); and because of this the view was not picked upped by findViewById.

这篇关于使用setEmptyView在ListActivity问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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