gpt4 book ai didi

android - setEmptyView 不适用于 ListView

转载 作者:行者123 更新时间:2023-11-29 17:42:39 26 4
gpt4 key购买 nike

所以我在 Fragment 中有一个 ListView,我在其上运行 listView.setEmptyView(getActivity().findViewById(R.id.emptyListView));

在我的 xml 文件中有

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nothing here yet! "
android:id="@+id/emptyListView"
android:visibility="gone"/>

ListView 在有数据时工作正常,但 TextView 在为空时不显示。我在这里做错了什么?

最佳答案

我会验证 findViewById() 是否返回非空值。

在 fragment 的 Root View 上尝试 .findViewById()。

关于android - setEmptyView 不适用于 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28028523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com