Android ApiDemos example resolution (175): Views-& gt; Lists-& gt; 8. Pho

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.