Skip to content

Instantly share code, notes, and snippets.

@wszdwp
Created December 11, 2019 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wszdwp/288b4fb0e5fd8fe292eaa555bc26ac43 to your computer and use it in GitHub Desktop.
Save wszdwp/288b4fb0e5fd8fe292eaa555bc26ac43 to your computer and use it in GitHub Desktop.
Demo for swipeRefreshLayout

How to use swipeRefreshLayout

Steps

  1. Add SwipeRefreshLayout as parent view to your listview
  2. Implement SwipeRefreshLayout.OnRefreshListener() by setOnRefreshListener
  3. Dimiss the refresh activity indicator

In layout (Step 1)

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_below="@id/inputLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/myList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="beforeDescendants" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

In activity (Step 2, 3)

swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        //TODO: Impl your action
    }
});

// When action done, dismiss the refresh activity indicator
if (swipeRefreshLayout.isRefreshing()) {
    swipeRefreshLayout.setRefreshing(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment