Android empty list layout
Android empty list layout
Whatever I do, I can't get the empty tag to display. Inside my tabs, I've got:
<LinearLayout
android:id="@+id/thisParticularTab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/LastUpdated"
android:layout_width="fill_parent"
androi开发者_运维问答d:layout_height="wrap_content"
android:text="List last updated: N/A" />
<ListView
android:id="@+id/mySpecialListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Click to fill the list" /></LinearLayout>
However despite my ListView being empty (no items are displayed, and the database table being read from is empty), the button is not displayed. Any ideas?
Also, when it appears, will I be able to refer to R.id.empty? Does this really mean I can only have 1 ListView/empty per activity? My understanding is that 'id' is used to define UI define; how can I give it a name and also assign it as the empty View within the XML? (I'd prefer not to use setEmptyView())
What you've missed here, is that the button id also needs the android prefix:
<Button
android:id="@android:id/empty"
... />
@android:id/empty
refers to android.R.id.empty
, not R.id.empty
.
It is true that you should only have one element of a given id per view. If you are creating your own list view item, you naturally have the same elements (and subsequently the same ID's) over and over, but in these occasions you can access them by myListItem.findViewById(id)
More related to your scenario, if you would find the need to add another listview, which takes another empty-tag, and still want the listview to inherently handle the hiding and showing of that item, you can use the function setEmptyView(id)
Try:
<Button id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Click to fill the list" />
And to find the button:
Button empty = (Button) findViewById(android.R.id.empty);
精彩评论