SwipeRefresh is not working after setting an empty view for listview which is the only child of a SwipeRefresh layout. How to solve this issue?
The problem for me was that when the empty view was visible then the refreshing circle wasn't shown although the refreshing method worked. For me this code worked, I hope it helps.
the xml layout:
the custom SwipeRefreshLayout:
package misc;
import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView;
public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {
private ListView mListView;
public CustomSwipeRefreshLayout(Context context) {
super(context);
}
public void setListView(ListView listView) {
mListView = listView;
}
@Override
public boolean canChildScrollUp() {
if (mListView == null) {
return true;
}
return mListView.canScrollVertically(-1);
}
}
and in my Fragment where I use the layout I only set the swipe to refresh layout in this way:
mSwipeRefreshLayout.setListView(mListView);
the ListView's empty view is set in this way:
TextView emptyView = (TextView) view.findViewById(R.id.empty_view);
emptyView.setText("No data");
mListView.setEmptyView(emptyView);
I hope it helps.