How to use swipeRefreshLayout
Add SwipeRefreshLayout as parent view to your listview
Implement SwipeRefreshLayout.OnRefreshListener() by setOnRefreshListener
Dimiss the refresh activity indicator
<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>
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 );
}