SwipeRefreshLayout 配合fragment 下拉刷新的使用,超級簡單


前台demo

<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:id="@+id/swipe_container"
android:layout_height="wrap_content"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/test_record"
android:layout_marginBottom="50dp"
>
</ListView>

</android.support.v4.widget.SwipeRefreshLayout>

后台的demo
因為界面是fragment 並不是一個activity,所以后台demo寫在了
public void onActivityCreated(@Nullable Bundle savedInstanceState){}
這個方法里面了,核心demo具體如下:
注意事項,我原來一直無法刷新,是因為在方法onRefresh,里面沒有寫加載數據的方法,仔細想一想,
做刷新處理,肯定是請求數據,所以,initScore(); 這個方法是直接請求數據。加進去就OK 了。

mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
my_record.setText("正在刷新");
// TODO Auto-generated method stub
test_type.clear();
test_score.clear();
test_time.clear();
initScore();
new Handler().postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
my_record.setText("刷新完成");
mSwipeLayout.setRefreshing(false);
}
}, 6000);
}
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM