Note that in this example, R. layout. in list_8.xml, The ListView and a TextView are displayed. the id of the TextView is @ + id/emtpy and placed in FrameLayout. When the ListView is empty, the TextView is displayed, "no photos" indicates that the Listview is empty:
[Html]
<! -The frame layout is here since we will be showing either
The empty view or the list view.->
<FrameLayout
Android: layout_width = "match_parent"
Android: layout_height = "0dip"
Android: layout_weight = "1">
<! -Here is the list. Since we are using a ListActivity, we
Have to call it "@ android: id/list" so ListActivity will
Find it->
<ListView android: id = "@ android: id/list"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: drawselectid Top = "false"/>
<! -Here is the view to show if the list is emtpy->
<TextView android: id = "@ + id/empty"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "@ string/list_8_no_photos"/>
</FrameLayout>
<! -The frame layout is here since we will be showing either
The empty view or the list view.->
<FrameLayout
Android: layout_width = "match_parent"
Android: layout_height = "0dip"
Android: layout_weight = "1">
<! -Here is the list. Since we are using a ListActivity, we
Have to call it "@ android: id/list" so ListActivity will
Find it->
<ListView android: id = "@ android: id/list"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: drawselectid Top = "false"/>
<! -Here is the view to show if the list is emtpy->
<TextView android: id = "@ + id/empty"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "@ string/list_8_no_photos"/>
</FrameLayout>
In fact, ListActivity provides a more concise way to display the View when the ListView is set to null. You can use any View in Layout by setting its id to "android: id/empty.
In this example, you can dynamically Add photos to the ListView and Clear the table. After changing the ListView data source, you must call yydatasetchanged () to notify the UI of the update screen.