I am struggling with a documentation in SwipeRefreshLayout
of Google's support library.
When I receive the refresh call using the callback set by setOnRefreshListener
, I do my action and after that, I found that I need to set the refresh state to false again - if I do NOT do that, I can never trigger it again by swiping!
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Toast.makeText(getApplication(), "Refreshing!", Toast.LENGTH_SHORT).show();
//requestDataRefresh();
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
So far, so good. But look at the documentation of setRefreshing
:
/**
* Notify the widget that refresh state has changed. Do not call this when
* refresh is triggered by a swipe gesture.
*
* @param refreshing Whether or not the view should show refresh progress.
*/
public void setRefreshing(boolean refreshing) {...
But setting the refresh state to false again is exactly what I have to do after refreshing!
Is the documentation wrong or am I seeing it wrong? Shouldn't the doc rather say: "Do not call this with refreshing state true when refresh is triggered by a swipe gesture"??
What do you think?
When you swipe SwipeRefreshLayout
from top to bottom, setRefreshing(true)
is triggered automatically. So you don't need to call setRefreshing(true)
repeatedly. Meanwhile, if you call setRefreshing(true)
but not swipe SwipeRefreshLayout
, you will see the same scene when you swipe SwipeRefreshLayout
. And no matter whether you call setRefreshing(true)
or swipe SwipeRefreshLayout
from top to bottom, you need to call setRefreshing(false)
after you finish your task. Just like you did in your code segment above.
I think it should probably say that there is no need to call this with true if you're refresh was triggered with the swipe gesture.
Incidentally, I found some issues when updating the UI in certain cases which were solved by wrapping the call like this:
private void setRefreshing(final boolean refreshing) {
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(refreshing);
}
});
}
}
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