Correct use of setemptyview in Android listview

Correct use of setemptyview in Android listview

We know that the listview component provides a view setting method for null data, setemptyview. There is a criticism of this method, that is, the null view and listview components should be in the same parent. This is not discussed in detail here. The following is another problem. The reason is actually the same as the previous problem.

If emptyview and listview belong to the same parent in the layout, the code for setting emptyview is as follows

If there is no data, operation, everything is normal.

Let's execute a sentence of code

We found that emptyview can't see it. Strange!

Let's take a look at the code of setemptyview of listview

Focus on the source code of updateemptystatus

We found that controlling the display of the emptyview is to hide the listview. The two try to hide the display from each other to achieve the effect. Moreover, the updateemptystatus method can only be executed when the setemptyview of the listview is executed. Therefore, when you execute mlist.setvisibility (view. Visible), the listview is set to visible, which overrides the emptyview, so you can't see it, If you want to display emptyview, execute the setemptyview method again.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>