Android ListView Setemptyview

Source: Internet
Author: User

Http://my.eoe.cn/yaming/archive/879.html

1
       When we use the ListView or GridView, when the list is empty, we need a special view to prompt the user to operate, so there is Setemptyview (). Let's see how to use:
1 2 3 4 5 6 7 8 910111213141516
<LinearLayoutxmlnsAndroid="Http://schemas.android.com/apk/res/android"Android:Orientation="Vertical"Android:Layout_width="Fill_parent"Android:Layout_height="Fill_parent"><ListviewAndroid:Layout_width="Fill_parent"Android:Layout_height= "fill_parent" android:id= "@+id /list_view "/> <textview android: id= "@+id/empty_list_view" android: layout_width= "wrap_content" android: layout_height= "wrap_content" android: text= "List view is empty" android: visibility= "Gone" /> </< span class= "n" >linearlayout>           
 123 
 listview list< Span class= "o" >=  (listviewfindviewbyid  (r. Id.textview tv=  (textview ) findviewbyid (r. Id.list. (tv        

Show Complex View

When the contents of the list are empty, they are displayed directly.
But sometimes we suggest that the view is complicated and we don't want to write in the same file I can think of:

123456
TextViewEmptyview=NewTextView(Context);Emptyview.Setlayoutparams(NewLayoutparams(Layoutparams.Fill_parent,Layoutparams.Fill_parent));Emptyview.SetText ( "this appears when the list is empty " emptyview. (view. Gone ((viewgroup) list. ()). addview (emptyviewlist. (emptyview        

Or

1234
Inflater=Getlayoutinflater();emptyview = inflater. Inflate (r. Layout.nulladdcontentview (emptyviewnew span class= "n" >layoutparams (layoutparams. Fill_parent,layoutparams. Fill_parentlist. (emptyview       
Attention:

1. Do not let the prompt view show up when not changing the display.

1
Emptyview.  Setvisibility(View.  GONE       

2.setEmptyView () This method is limited, this view must be in the current view hierarchy node, we can write ourselves in the current layout file, can also be written on the outside, but need to add the view to the current view On the Hierarchy node. 、

123
((viewgroup)list.  GetParent()). AddView(emptyview//or Addcontentview(emptyviewlayoutparams(  Layoutparams.  Fill_parent,layoutparams.  Fill_parent                

^_^ Welcome Message

Here with three kinds of QQ address book to do the display:

[Java]View Plaincopy
    1. TextView Emptyview = new TextView (this);
    2. Emptyview.setlayoutparams (new Layoutparams (Layoutparams.match_parent,
    3. Layoutparams.match_parent));
    4. Emptyview.settextcolor (Getresources (). GetColor (
    5. R.color.texttasktypecolor));
    6. Emptyview.settext ("No Office Store points list Information");
    7. Emptyview.setvisibility (View.gone);
    8. Emptyview.setgravity (Gravity.center);
    9. ((ViewGroup) mlistview.getparent ()). AddView (Emptyview);
    10. Mlistview.setemptyview (Emptyview);
    11. Setting up data
    12. adapter = new Shopdetailreportadapter ();
    13. Mlistview.setadapter (adapter);

Android ListView Setemptyview

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.