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 empty textview to the following working XML file:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listViewConversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dp" />
</android.support.v4.widget.SwipeRefreshLayout>
Wrapping it in a Linear/Relative layout makes it buggy because the listview will always update when you want to slide back up the listview. One way I can think of is doing this programmatically but I guess that's not the best option.
You can learn how to implement it using this tutorial: Swipe to refresh GUIDE
So basically it all works fine but I would like to add an empty view that shows a message when the listview is empty.
Probably late, But if you're still facing this issue, Here is the clean solution! There is no need of creating another
SwipeRefreshLayout
.wrap
empty view
into aScrollView
. Stick bothAdapterView
and theScrollView
into aViewGroup
and put it into theSwipeRefreshLayout
Sample:
EDIT
Here is much more simpler way.
check if your list is empthy. if yes then make it invisible. Sample:
this will make
mRecyclerView
still there and all swipes will be working fine now even there is no data!As i mentioned here, i have done this for
RecyclerView
:I have used
clickable="true"
like below with emptyRecyclerView
:xml layout:
RecyclerView
has heightmatch_parent
andSwipeRefresh
haswrap_content
. When there is item in list, don't forget to make textgone
.I encountered the same problem. It is annoying that SwipeRefreshLayout can only have one AdpaterView child.
If an empty view is set for an AdpaterView, it will be set as hidden if no data is available. However, SwipeRefreshLayout needs an AdpaterView to work. So, I extend AdpaterView to make it still shown, even if it is empty.
Maybe you need to set the background of adapter view as transparent as well. But in my case, it is not needed, as the empty view is a simple TextView.