I\'ve implemented SwipeRefreshLayout into my app but it can only hold one direct child which should be the listview. I\'m trying to figure out how to add an emp
This was a very frustrating issue for me but after a few hours with try and fail I came up with this solution.
With this I can refresh even with empty view visible (and RecyclerView too of course)
In my layout file I have this structure:
SwipeRefreshLayout
FrameLayout
RecyclerView
my_empty_layout // Doesnt have to be ScrollView it can be whatever ViewGroup you want, I used LinearLayout with a single TextView child
In code:
...
adapter.notifyDataSetChanged()
if (adapter.getItemCount() == 0) {
recyclerView.setVisibility(View.GONE);
emptyView.setVisibility(View.VISIBLE);
}
else {
recyclerView.setVisibility(View.VISIBLE);
emptyView.setVisibility(View.GONE);
}