Use SwipeRefreshLayout
from support-v4 https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
Wrap the ListView in a SwipeRefreshLayout in xml:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
And set the listener in your onCreate()
:
SwipeRefreshLayout swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(this);
and implement it
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swipe.setRefreshing(false);
}
}, 5000);
}