How to disable "pull to refresh" action and use only indicator?

Александр Шевчук picture Александр Шевчук · May 18, 2015 · Viewed 41.8k times · Source

I enabled "pull to refresh" to my project using the SwipeRefreshLayout.

When I move down, appear the loading indicator (material design style). I know, it must so work, but I want to disable this function, and start refreshing by click some button and use SwipeRefreshLayout loading indicator.

How I can to do this?

Answer

nhasan picture nhasan · May 19, 2015

From the documentation:

If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.

So to show the animation:

swiperefreshLayout.setEnabled(true);
swiperefreshLayout.setRefreshing(true);

And to hide the animation:

swiperefreshLayout.setRefreshing(false);
swiperefreshLayout.setEnabled(false);