@android:id / empty显示空视图,但在ListFragment中存在数据时不显示ListView(@android:id/empty shows empty view, but doe

编程入门 行业动态 更新时间:2024-10-14 06:21:11
@android:id / empty显示空视图,但在ListFragment中存在数据时不显示ListView(@android:id/empty shows empty view, but does not show the ListView when data exists in ListFragment)

我有一个具有以下布局的ListFragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingLeft="8dp" android:paddingRight="8dp" > <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:drawSelectorOnTop="false" > </ListView> <TextView android:id="@android:id/empty" android:layout_width="match_parent" android:layout_height="match_parent" android:text="No data" /> </LinearLayout>

最初创建ListFragment时,它没有数据,一切都很好。 “无数据”文本视图按预期显示。

但是当我添加内容/数据时,ListFragment仍保留在“无数据”视图中,并且不会切换到显示行。 如果我取出XML的@android:id / empty部分,那么我可以看到行完全正常。 这意味着它不是输入数据的问题,而是关于实际XML文件的问题(我相信)。

有什么方法可以解决这个问题吗?

更新:添加到List时调用notifyDataSetChanged()解决了这个问题!

I have a ListFragment with the following layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingLeft="8dp" android:paddingRight="8dp" > <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:drawSelectorOnTop="false" > </ListView> <TextView android:id="@android:id/empty" android:layout_width="match_parent" android:layout_height="match_parent" android:text="No data" /> </LinearLayout>

When the ListFragment is initially created it has no data and everything is fine. The "no data" textview is shown as expected.

But when i add content/data the ListFragment remains in the "No Data" view, and does not switch to showing the rows. If i take out the @android:id/empty portion of the XML then i can see the rows perfectly fine. This means that it is not an issue of inputting data, but an issue regarding the actual XML file (i belive).

Is there any way to remedy this?

Update: Calling notifyDataSetChanged() when adding to the List resolved this issue!

最满意答案

如果将此代码添加到片段中,在listview上设置适配器,该怎么办? list.setEmptyView(findViewById(android.R.id.empty))?

What if you add this code to the fragment, where you set an adapter on the listview? list.setEmptyView(findViewById(android.R.id.empty)) ?

更多推荐

本文发布于:2023-08-07 02:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但在   视图   数据   ListFragment   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!