我有一个具有以下布局的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)) ?
更多推荐
发布评论