In the past when using the ListView or GridView, if you want to add a friendly reminder without content, it is in the same location of the ListView or GridView, add a ImageView, Then through the control of the Visibile set to View.visible or View.gone method settings, although this can also be achieved, but is undoubtedly more cumbersome, and now we have a better way to implement, that is, using Viewswitcher
The sample code is as follows:
<viewswitcher android:id= "@+id/vs_dynamic" android:layout_width= "Match_parent" android:layout_height= "155DP" android:layout_margin= "10DP" > < ; ListView android:id= "@+id/lv_dynamic" style= "@style/listviewbackground" Android:layout_width= "Match_parent" android:layout_height= "155DP" android:layout_margin= "10DP" > </ListView> <imageview Android:id= "@+id/iv_dynamic_nocontent" style= "@style/listviewbackground" Android:layout_width= "Match_parent" android:layout_height= "155DP" Android:layout_margin= "10DP" android:src= "@drawable/viewpager3" Android:vis ibility= "Visible" > </ImageView> </ViewSwitcher>
Find our Viewswitcher by ID in our program
<pre name= "code" class= "java" ><pre name= "code" class= "java" ><span style= "font-family:arial, Helvetica , Sans-serif; " >viewswitcher </span><span style= "font-family:arial, Helvetica, Sans-serif;" >dynamicviewswitcher = (viewswitcher) Findviewbyid (r.id.vs_dynamic);</span>
And then through
Dynamicviewswitcher.setdisplayedchild (1);
To set which child view we are going to show, in the use of the control, it is important to note that Viewswitcher can only have two sub-views, otherwise it will be abnormal, if you want to add more complex view
We can consider using layout and nesting with layout
Android Viewswitcher enables easy switching of views