Skip to content

Instantly share code, notes, and snippets.

@gbzarelli
Created July 26, 2018 16:12
Show Gist options
  • Save gbzarelli/f55bc5926651edc496ee375a0a97105c to your computer and use it in GitHub Desktop.
Save gbzarelli/f55bc5926651edc496ee375a0a97105c to your computer and use it in GitHub Desktop.
SwipeRefreshLayout
protected SwipeRefreshLayout swipe;
swipe = layout.findViewById(swipeId);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
sendRequest();
}
});
protected void showProgress() {
swipe.post(new Runnable() {
@Override
public void run() {
swipe.setRefreshing(true);
}
});
}
protected void stopRequest() {
swipe.postDelayed(new Runnable() {
@Override
public void run() {
swipe.setRefreshing(false);
}
}, 1000);
}
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:scrollbars="vertical"
app:layoutManager="LinearLayoutManager" />
</android.support.v4.widget.SwipeRefreshLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment