0

I wish someone could take a look on that and let me know what is wrong.this is my emptyView container in the activity_main

<ListView
        android:id="@+id/display_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RelativeLayout
        android:id="@+id/empty_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <TextView
            android:id="@+id/empty_shelter_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:fontFamily="sans-serif-medium"
            android:paddingTop="16dp"
            android:text="@string/empty_view_title_text"
            android:textAppearance="?android:textAppearanceMedium" />

        <TextView
            android:id="@+id/empty_subtitle_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/empty_shelter_title"
            android:layout_centerHorizontal="true"
            android:fontFamily="sans-serif"
            android:paddingTop="8dp"
            android:text="@string/empty_view_sub_text"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#A2AAB0" />

    </RelativeLayout>

I have set emptyView in each fragment, and even though when items are showing in the list it is still showing the empty view fields.

//set empty activity
    ListView listView = rootView.findViewById(R.id.display_view);
    View emptyView = rootView.findViewById(R.id.empty_view);
    listView.setEmptyView(emptyView);
    //create a new cursor adapter
    mCursorAdapter = new PlatformCursorAdapter(getActivity(),null);
    listView.setAdapter(mCursorAdapter);

I will highly appreciate it if you can tell me what i did wrong.

Wissam
  • 17
  • 5
  • why sending `null`. You should pass `LIST`. – IntelliJ Amiya May 17 '18 at 05:34
  • I'm working as per a previous app, second argument was being to set to null as well. – Wissam May 17 '18 at 05:39
  • That code appears to be in `Fragment`, by you've said the layout is named `activity_main`. If this is the same code as in [your previous question](https://stackoverflow.com/q/50342800), then the problem is that you're using the same layout in both the `Activity` and the `Fragment`, and empty `View` in the `Activity` is never going to be hidden by the `ListView` in the `Fragment`. You want to use a separate layout for the `Fragment`, containing the `ListView` and empty `View`, and remove those from `activity_main`. – Mike M. May 17 '18 at 05:45
  • https://stackoverflow.com/questions/12483508/setemptyview-on-listview-not-showing-its-view-in-a-android-app – rya May 17 '18 at 05:47

2 Answers2

3

Try hiding the empty_view in xml.

<RelativeLayout
        android:id="@+id/empty_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_centerInParent="true">
Deˣ
  • 4,191
  • 15
  • 24
0

my friends you have a send a null in adapter. send a list

mCursorAdapter = new PlatformCursorAdapter(getActivity(),null);

and other way are used to check a listview is null hide the display_view view and show the empty_view .

Ashwani kumar
  • 164
  • 15