I need help. I have a Listview.setListAdapter(arrayAdapter) and array adapter have a arrayList.
If my arrayList is empty it shows loading images, it is normal, but how can i show a message if my arrayList is empty? Thanks in advance.
just check if (cartlist. size()<0) then yours list is Empty.!
The common way is setting an empty textview (@android:id/empty) after the listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dividerHeight="1dp" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty_list" />
</LinearLayout>
And then set set the empty view to the listview:
ListView lv = (ListView)findViewById(android.R.id.list);
TextView emptyText = (TextView)findViewById(android.R.id.empty);
lv.setEmptyView(emptyText);
This should show items in the list whenever they are, and show the textview when not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With