Quickly handle the case where the listview is empty

List display is often used in mobile development. For list display, we often use listview control. There are usually two situations when displaying a list:

1、 The list is full;

2、 The list is empty;

What should we do when there is no data? There is a simple way to solve the problem. Let's take a look.

Listview and other classes inherited from AdapterView can use the setemptyview (view) method to set the display in the empty state. When the adapter drawing AdapterView is empty or the isempty method returns true, the view set by the setemptyview (view) method will be displayed.

For example, we display the following view on the interface.

An ImageView is displayed under the listview. Note that during the test, I found that the ImageView must be set to Android: visibility = "gone". Otherwise, it will be displayed regardless of whether the listview adapter is empty or not.

In activity, we can set it as follows:

In this way, when our data is empty, we can set empty_ listview_ lv.setAdapter(null); This will display ImageView (Note: it is not necessary to set the visibility of ImageView to visible);

Attachment: data display

No data display

The above quick processing listview is empty, which is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>