Google自己的下拉刷新组件SwipeRefreshLayout
关系图
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.support.v4.widget.SwipeRefreshLayout
1 @Bind(R.id.rotate_header_grid_view_frame) 2 SwipeRefreshLayout refreshTool; 3 4 refreshTool.setSize(SwipeRefreshLayout.DEFAULT); 5 refreshTool.setColorSchemeResources(R.color.holo_blue_light_new 6 ,R.color.holo_blue_light_new, 7 R.color.holo_blue_light_new,R.color.holo_blue_light_new); 8 refreshTool.setProgressBackgroundColor(R.color.linelogin); 9 refreshTool.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 10 @Override 11 public void onRefresh() { 12 getData(); 13 } 14 });
1
/** 2 * 获取所有的处方 3 */ 4 protected void getData() { 5 Call<List<PrescriptionBean>> call = prescriptionService.LoadPrescriptionsByPatientId(patientId); 6 call.enqueue(new Callback<List<PrescriptionBean>>() { 7 @Override 8 public void onResponse(Call<List<PrescriptionBean>> call, Response<List<PrescriptionBean>> response) { 9 if (refreshTool != null) { 10 refreshTool.setRefreshing(false); 11 } 12 if (response.isSuccessful()) { 13 List<PrescriptionBean> prescriptionList = response.body(); 14 list.clear(); 15 list.addAll(prescriptionList); 16 prescriptionAdapter.notifyDataSetChanged(); 17 18 } 19 } 20 21 @Override 22 public void onFailure(Call<List<PrescriptionBean>> call, Throwable t) { 23 showToast(LoadingStatu.NetError.value); 24 if (refreshTool != null) { 25 refreshTool.setRefreshing(false); 26 } 27 } 28 }); 29 }