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

AndroidMaterial DesignPull to-RefreshSwiperefreshlayout

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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);

Solution 2 - Android

You don't have to always enable and disable. Just disable once when the view is created and then use setRefreshing.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionАлександр ШевчукView Question on Stackoverflow
Solution 1 - AndroidnhasanView Answer on Stackoverflow
Solution 2 - AndroidMichał JanowiczView Answer on Stackoverflow