1. Customizing the native Swiperefreshlayout
public class Autoswiperefreshlayout extends Swiperefreshlayout {
Public Autoswiperefreshlayout (Context context) {
Super (context);
}
Public Autoswiperefreshlayout (context context, AttributeSet Attrs) {
Super (context, attrs);
}
/**
* Auto Refresh
*/
public void AutoRefresh () {
try {
Field Mcircleview = SwipeRefreshLayout.class.getDeclaredField ("Mcircleview");
Mcircleview.setaccessible (TRUE);
View progress = (view) mcircleview.get (this);
Progress.setvisibility (VISIBLE);
Method setrefreshing = SwipeRefreshLayout.class.getDeclaredMethod ("setrefreshing", Boolean.class, Boolean.class);
Setrefreshing.setaccessible (TRUE);
Setrefreshing.invoke (This, true, true);
} catch (Exception e) {
E.printstacktrace ();
}
}
}
2. Call the AutoRefresh () method directly when using to refresh automatically
3. You need to add a hint that is refreshing or loading: You can re-layout, add TextView implementation
The XML file is as follows
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<textview
Android:id= "@+id/tv_loading"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:padding= "@dimen/dp_5"/>
<com.shzx.zcyg.customview.autoswiperefreshlayout
Android:id= "@+id/refresh_list"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" >
<relativelayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<textview
Android:id= "@+id/tv_no_content"
style= "@style/title_second_setting"
Android:layout_centerinparent= "true"
android:layout_gravity= "Center"
android:layout_margintop= "@dimen/dp_20"
android:text= "@string/no_content"
android:visibility= "Gone"/>
<android.support.v7.widget.recyclerview
Android:id= "@+id/lv_detail"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
</RelativeLayout>
</com.shzx.zcyg.customview.AutoSwipeRefreshLayout>
</LinearLayout>
4. Implementation code:
Refreshsetonrefreshlistener (New Swiperefreshlayout.onrefreshlistener () {
@Override
public void Onrefresh () {
Tv_loading.settext (r.string.data_loading);
New Handler (). postdelayed (New Runnable () {
@Override
public void Run () {
Add data that needs to be refreshed
GetData ();
Refresh_order.setrefreshing (FALSE);
if (total_page==0) {
Tv_loading.setvisibility (View.gone);
Tv_no_content.setvisibility (view.visible);
}
}
}, 3000);
}
});
Refresh of page Add timer in Android