如何為你的應用新增刷卡重新整理

確保在依賴項下的應用程式的 build.gradle 檔案中新增了以下依賴項:

compile 'com.android.support:support-core-ui:24.2.0'

然後在佈局中新增 SwipeRefreshLayout

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

     <!-- place your view here -->       

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

最後實現 SwipeRefreshLayout.OnRefreshListener 監聽器。

mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
         // your code
    }
});