0

I have seen many tutorial and other things here to set the empty view when the list is empty. I have a list that is able to swipe to refresh. Now I want to show a text message in a text view when the list view is null. I have come to know that it can be simple set lik this

myListview.setEmptyView(mEmptyViewContainer);

but it is not setting the textview when the data is null in the listview. The following is the modification of my xml after reading an issue which he resolved by wrapping the text view in the separate swipeRefreshLayout . Just see below, this is my xml now

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dadada"

    >
        <RelativeLayout
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
       >

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />




</android.support.v4.widget.SwipeRefreshLayout>
        </RelativeLayout>
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeRefreshLayout_emptyView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sdasdadadfdasf"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:gravity="center"
        /></ScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

So now I do not understand why it is not showing my empty view? what can be the problem ? Or please tell me if there is another way to do this? the code snippet would be appreciated.

Coas Mckey
  • 701
  • 1
  • 13
  • 39
  • Kind of a related question: I too have a `com.baoyz.swipemenulistview.SwipeMenuListView` within a `SwipeRefreshLayout`. But the left swipe gesture somehow conflicts with the pull-to-refresh gesture. I have to left swipe with a lot more force and all the way to the left to reveal the underlying context buttons. It just isn't natural to do that. Is there some kind of sensitivity setting or some other fix to avoid this conflict? Have you experienced something like this too? – Shiprack Jan 26 '16 at 13:17
  • Found [this](http://stackoverflow.com/questions/23989910/horizontalscrollview-inside-swiperefreshlayout) - a customized SwipeRefreshLayout to solve my problem. – Shiprack Jan 27 '16 at 12:21

1 Answers1

0

You can do like this:

in your xml:

<RelativeLayout>
    <SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout">
    </SwipeRefreshLayout>
    <TextView
        android:id="@+id/layout_empty"/>
</RelativeLayout>

java code:

swipeView = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_refresh_layout);
layoutEmpty = getActivity().findViewById(R.id.layout_empty);

when the list view is null:

layoutEmpty.setVisibility(View.VISIBLE);

when the list view is not null:

layoutEmpty.setVisibility(View.INVISIBLE);
Norutan
  • 1,480
  • 2
  • 14
  • 27