I want to show you an empty view when the list view is empty.

Asked 2 years ago, Updated 2 years ago, 110 views

<RelativeLayout android:id="@+id/LinearLayoutAR"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <ListView android:id="@+id/ARListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"></ListView>
    <ProgressBar android:id="@+id/arProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"></ProgressBar>
    <!-- Here is the view to show if the list is emtpy -->
    <TextView android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="No Results" />
</RelativeLayout>

There are several reasons for showing an empty view as a text view. The problem is that this text view always comes out. Even if the list view is not empty. I thought it would automatically detect if the list view was empty, but it wasn't.

android listview relativelayout

2022-09-22 22:13

1 Answers

<TextView android:id="@android:id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="No Results" />

Just do it like this. The problem is android:id="@android:id/empty" this part.


2022-09-22 22:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.