In the use of the official control swiperefreshlayout, found that the original Emptyview disappeared, in the online search for a lot of information, did not match my answer, because my emptyview is a help class to achieve, and then the hundred setbacks, finally found a perfect way , introduced as follows:
First, change the layout of the XML, add a layer of framelayout outside, and the improved XML layout is as follows:
<framelayout android:id= "@+id/parent" android:layout_width= "Match_parent" android:layout_height= " 0DP "android:layout_weight=" 1 "> <android.support.v4.widget.swiperefreshlayout android:id=" @ +id/swipe_container "android:layout_width=" match_parent "android:layout_height=" match_parent "> < ; TextView android:id= "@+id/empty_textview" android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:text= "Empty_textview" android:textsize= "25SP" /> <listview android:id= "@+id/listview" Android:layout_widt H= "Match_parent" android:layout_height= "match_parent" android:background= "@color/white" android:scrollbarstyle= "Outsideoverlay"/> </android.support.v4.widget.swipere Freshlayout> </framelayout>
The reason for this is because Swipelayout is viewgroup, can not directly addview, or say yes, but AddView is no effect, so nested a framelayout outside, with this layout to add Emptyview , here is the Help class for Emptyview
public class Emptyviewhelper {private ListView mlistview;private View emptyview;private Context mcontext;private String m Emptytext;private TextView mtextview;private framelayout parent;public emptyviewhelper (ListView ListView, String Text) {Mlistview = Listview;mcontext = Listview.getcontext (); memptytext = Text;initemptyview ();} Public Emptyviewhelper (ListView ListView, String Text, framelayout parent) {Mlistview = Listview;mcontext = Listview.getc Ontext (); memptytext = Text;this.parent = Parent;initemptyview ();} private void Initemptyview () {Emptyview = View.inflate (mcontext, R.layout.empty_view, NULL); Layoutparams LP = new Layoutparams (layoutparams.wrap_content, layoutparams.wrap_content, gravity.center_horizontal); Parent.addview (Emptyview, LP); Mlistview.setemptyview (Emptyview); Textutils.isempty (Memptytext)) {((TextView) Emptyview.findviewbyid (R.id.textview)). SetText (Memptytext);}}
In this case, for a ListView that needs to add Emptyview, use the following code directly to achieve
Emptyviewhelper emptyviewhelper = new Emptyviewhelper (Mlistview, "Loading", (framelayout) V.findviewbyid (R.id.parent));
This way, the Emptyview effect of the ListView is out.
In the gradual development process, found that the code reuse more and more important, for the same function, can use the Help class to achieve, as far as possible with the help class, reduce the workload of our Code, the same work later, as long as very little code can be achieved, or the same module, but only need very little code, such a method, In the late update, but also as long as the update of a module, all are updated, suitable for use in the work.
Android Development: Swiperefreshlayout cannot display Emptyview