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
- TextView Emptyview = new TextView (this);
- Emptyview.setlayoutparams (new Layoutparams (Layoutparams.match_parent,
- Layoutparams.match_parent));
- Emptyview.settextcolor (Getresources (). GetColor (
- R.color.texttasktypecolor));
- Emptyview.settext ("No Office Store points list Information");
- Emptyview.setvisibility (View.gone);
- Emptyview.setgravity (Gravity.center);
- ((ViewGroup) mlistview.getparent ()). AddView (Emptyview);
- Mlistview.setemptyview (Emptyview);
- Setting up data
- adapter = new Shopdetailreportadapter ();
- Mlistview.setadapter (adapter);
Android ListView Setemptyview