java - 即使列表不为空,emptyView 也始终显示
问题描述
我希望有人可以看一下,让我知道出了什么问题。这是我在 activity_main 中的 emptyView 容器
<ListView
android:id="@+id/display_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/empty_shelter_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-medium"
android:paddingTop="16dp"
android:text="@string/empty_view_title_text"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="@+id/empty_subtitle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/empty_shelter_title"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif"
android:paddingTop="8dp"
android:text="@string/empty_view_sub_text"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#A2AAB0" />
</RelativeLayout>
我在每个片段中设置了 emptyView,即使项目显示在列表中,它仍然显示空视图字段。
//set empty activity
ListView listView = rootView.findViewById(R.id.display_view);
View emptyView = rootView.findViewById(R.id.empty_view);
listView.setEmptyView(emptyView);
//create a new cursor adapter
mCursorAdapter = new PlatformCursorAdapter(getActivity(),null);
listView.setAdapter(mCursorAdapter);
如果你能告诉我我做错了什么,我将不胜感激。
解决方案
尝试在 xml 中隐藏 empty_view。
<RelativeLayout
android:id="@+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_centerInParent="true">
推荐阅读
- android - android连接restful api和mvvm模式
- c++ - 用 Qt 解析 JsonDocument 的最佳方式
- calendar - 如何使用 webcal 协议
- .net - 无法在 .NET 5 Winforms 中加载文件或程序集“System.Runtime,Version=5.0.0.0”
- android - 无论出现在 xml 中,都隐藏底部导航视图
- python-3.x - 使用 Telethon 向电报中的所有联系人发送“hi”
- python - 如何为可以将值划分为类的列创建python函数
- flutter - 没有为“CollectionReference”类型定义方法“getDocuments”
- python - 如何制作这个 sha256 pow
- javascript - Ajax 不在数据库中保存数据