Make sure the following dependency is added to your app's build.gradle
file under dependencies:
compile 'com.android.support:support-core-ui:24.2.0'
Then add the SwipeRefreshLayout
in your layout:
<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>
Finally implement the SwipeRefreshLayout.OnRefreshListener
listener.
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// your code
}
});