即使listView中有元素,listView.SeptEmptyView也始终显示

时间:2013-03-18 10:03:50

标签: android android-listview android-fragments

即使ListView中有记录,ListView中的emptyView也会一直显示。 我正在使用SherlockFragment,我正在显示ListView,代码如下:

ViewGroup vg = (ViewGroup) getActivity().getLayoutInflater().inflate(
                R.layout.header_file, hotelListView, false);
        hotelListView.addHeaderView(vg, null, false);
        hotelListView.setOnItemClickListener(this);
        hotelListView.setEmptyView(view.findViewById(R.id.empty));

和xml:

 <ListView
        android:id="@+id/hotel_list_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:paddingLeft="8dp"
        android:persistentDrawingCache="scrolling"
        android:scrollingCache="false" >
    </ListView>

    <TextView
        android:id="@android:id/empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="No Results" />

因此,在从服务器检索结果后,TextView仍然显示在屏幕上,我可以在屏幕上看到No Results文本,同时列表中有项目。我需要更改什么,以便只有当列表中没有元素时才会显示@android:id / empty?感谢

1 个答案:

答案 0 :(得分:1)

如果不考虑来源,我可以想到3个可能的错误,

  1. ListView没有设置适配器。

  2. 如果重新实现了适配器,是否正确重新实现了getCount()方法?

  3. 你必须调用notifyDatasetChanged()吗?从服务器获取内容后。

相关问题