Listview spinner/loader that doesn't disappear

34 Views Asked by At

in my xml I have a listview that I fill with an adapter.

                <ListView
                android:id="@+id/listPartenaires"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="12dp"
                android:layout_marginRight="16dp"
                android:divider="@null" />

When I scroll down the page, I go to add more items and at the end of the listview for a few moments a spinner/loader appears which then disappears by itself when the rows are displayed.

If I scroll several times and then do a search going to show less rows than previously shown the spinner always remains displayed to me.

I would like to figure out how to hide it, considering that I don't have a real spinner object/widget in the view

Thanks

enter image description here

1

There are 1 best solutions below

1
Oyindamola Gideon Olarewaju On

If you're loading data into your ListView using a background thread or coroutines (asynchronously), you might be having problems with the loading indicator's lifecycle, making it lifecycle aware is important.

Here are a few things you can note:

  1. Display the Spinner: You have the option to display a loading indicator when you begin loading data, such as when you add new items. A ProgressBar or any other kind of visual cue can be used. You can showloading spinner.

  2. Hide the Spinner: The loading indication should be hidden after the data has finished loading. Ensure that the UI thread is used for this.

  3. Handling Edge Cases: Make sure you are calling the hide function even when the dataset is empty or there is an error.