1 answer
SwipeRefreshLayout from the Android library support - “pull to update” It adds functionality, which one of my colleagues calls “gum from cowards”, and the rest know this UI-pattern called “pull to update”. It is needed when there is some content that the user wants to update frequently, and can do it by simply pulling the content with a gesture down and then releasing.
It is very similar that the component was created for GoogleNow, and then migrated to support lib (the animation is very similar).
The algorithm is simple. The component “wraps around” around View or Layout , for which you need to make an update and can contain only one descendant (similar to ScrollView ). It is set to OnRefreshListener with a single onRefresh() method. How to respond to it - decide for yourself. When you need to show that the update is in progress (and start the animation), we call the setRefreshing(boolean) method and pass it true . The most logical is a method call inside onRefresh() . When the update is complete, call the setRefreshing(boolean) method and pass it false .
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:id="@+id/container" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> Logic can write here:
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // Do some logic // if (refresh is ok) Toast.makeText(getContext(), "Refresh", Toast.LENGTH_SHORT).show(); } }); 