天天看點

SwipeRefreshLayout簡單使用

SwipeRefreshLayout簡單使用

  • 簡單的下拉重新整理控件..在suportv4中
    //控件包住的内容進行重新整理
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_widget"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/home_recycler_view"
        android:scrollbars="vertical"
        android:background="#f1f1f1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    
    </android.support.v4.widget.SwipeRefreshLayout>
               
  • 簡單使用
    //設定下拉重新整理監聽..異步拉取資料..資料處理完畢停止重新整理
     mSwipeRefreshWidget.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    Logger.w("正在調重新整理哦", "......");
                    UIUtils.Toastshort(mActivity, "我開始重新整理了哦");
                    new Thread() {
                        @Override
                        public void run() {
                            super.run();
                            try {
                                sleep(2000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            mActivity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    //停止重新整理
                                    mSwipeRefreshWidget.setRefreshing(false);
                                }
                            });
                            UIUtils.Toastshort(mActivity, "重新整理成功");
                        }
                    }.start();
                }
            });