2

i am using a normal activity where in i have a listview. when the array is empty, how do i show an empty view? i tried using a textview with the id android:empty but it only works with listactivity. i am using a custom adapte(which extends the baseadapter class) for the listview and in the getcount() i return 0 when the array is null. But this is not working. i want to show a empty listview when i have no rows in my array. how do i achieve this?

thank you in advance.

3 Answers 3

3

Consider using a ListView and extending ListAdapter, which provide support for the empty case. Using these, a ListView element:

<ListView android:id="@+id/android:list" ... />

will display a matching

<TextView android:id="@+id/android:empty" ... /> 

for an empty list.

Sign up to request clarification or add additional context in comments.

Comments

1

Another tip I spent two hours figuring out. If you set the layout_height to "0dip" for the TextView as is sometimes recommended for efficiency, it won't show up unless you set the layout_weight to some value.

Comments

0

You can call set list.setEmptyView(view) to display any view when the list is empty.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.