0.build.gradle

  compile 'com.android.support:support-v4:23+'

1.布局文件  

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>

2.java代码

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);
ButterKnife.bind(this);
/** 绑定事件 */
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// 网络请求
request();
}
});     // 第一次打开自动刷新
    swipeRefreshLayout.measure(0, 0);
    swipeRefreshLayout.setRefreshing(true);
    request();
    }

    private void request() {
HttpUtil.getInstance().get(new HttpUtil.Builder()
.url("/scloudmenu/menu/16/list?key=&token=95af71ee-abb9-41cd-b8fd-f2f0a2bf16c0")
.params("currentPage", ++currentPage + "")
.callBackSuccess(new CallBackSuccess() {
@Override
public void onSuccess(String json) { //拿到请求数据,相当于 handleMessage() 中的处理
CloudMenuEntityList data = JsonUtil.fromJson(json, CloudMenuEntityList.class);
entityList.addAll(data.cloudMenuEntityList);
tv.setText(entityList.size() + ""); // 取消刷新效果
swipeRefreshLayout.setRefreshing(false);
}
})
);
}
05-11 17:45