I previously was using API 19 and was using SwipeRefreshLayout
for many of my fragments. When I loaded content for the first time previously, I was using the setRefreshing(true);
and was able to load content and it worked fine.
I'm noticing in Android 5.0 Google is using a circular progress view. When I call setRefreshing(true);
now it simply has no effect. Is there anyway to programmatically show the new spinner? I've delved in to this quite a bit but not able to programmatically show it. I have read the following on this:
http://developer.android.com/tools/support-library/index.html
https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/
SwipeRefreshLayout doesn't show any indicator of refreshing
Basically, it shows no indication of refreshing on the first try.
Android SwipeRefreshLayout is a ViewGroup that can hold only one scrollable child. It can be either a ScrollView, ListView or RecyclerView. The basic need for a SwipeRefreshLayout is to allow the users to refresh the screen manually. This is pretty common in the Facebook Newsfeed screen.
If the listener determines there should not be a refresh, it must call setRefreshing(false) to cancel any visual indication of a refresh. 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.
Instead of directly setting
getSwipeRefreshLayout().setRefreshing(true);
you can delay it on the UI thread for later
getSwipeRefreshLayout().post(new Runnable() {
@Override public void run() {
getSwipeRefreshLayout().setRefreshing(true);
}
});
this works perfectly for me to start loading in onCreateView
and if done in a LoaderManager.LoaderCallbacks
too.
I haven't seen the progress bar accidentally sticking (because the data load is too quick), but if you suspect that the load may return too early (error?) it's worth to do the same posting for
getSwipeRefreshLayout().setRefreshing(false);
this way the two post
s will definitely come one after the other, resulting in a definitely hidden progress view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With