Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use setEmptyView in Android

Shulou Source: shulou.com Published: 2022-05-31 23:51:50 09月21日 Update

Most people do not understand the knowledge points of this article "how to use setEmptyView in Android", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use setEmptyView in Android" article.

Correct use of setEmptyView in Android ListView

If emptyView and listview already belong to the same parent in the layout, the code to set EmptyView is as follows

Private void setEmptyView () {emptyTv.setText (getString (R.string.txt_no_data_refreshable)); mList.setEmptyView (empty);}

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

After we execute a sentence of code,

MList.setVisibility (View.VISIBLE)

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

Let's take a look at listview's setEmptyView code.

Public void setEmptyView (View emptyView) {mEmptyView = emptyView; / / If not explicitly specified this view is important for accessibility. If (emptyView! = null & & emptyView.getImportantForAccessibility () = IMPORTANT_FOR_ACCESSIBILITY_AUTO) {emptyView.setImportantForAccessibility (IMPORTANT_FOR_ACCESSIBILITY_YES);} final T adapter = getAdapter (); final boolean empty = ((adapter = = null) | | adapter.isEmpty ()); updateEmptyStatus (empty);}

It focuses on the source code of updateEmptyStatus.

Private void updateEmptyStatus (boolean empty) {if (isInFilterMode ()) {empty = false;} if (empty) {if (mEmptyView! = null) {mEmptyView.setVisibility (View.VISIBLE); setVisibility (View.GONE);} else {setVisibility (View.VISIBLE);} if (mDataChanged) {this.onLayout (false, mLeft, mTop, mRight, mBottom) }} else {if (mEmptyView! = null) mEmptyView.setVisibility (View.GONE); setVisibility (View.VISIBLE);}}

We found that to control the display of emptyView is to hide listview, the two try to hide the display from each other to achieve the effect, and the updateEmptyStatus method will only be executed when listview's setEmptyView, so when you execute mList.setVisibility (View.VISIBLE), listview is set to be visible, it overrides emptyView, so you can't see it, if you want to show emptyView, execute the setEmptyView method again.

The above is about the content of this article on "how to use setEmptyView in Android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Content code method that is articles knowledge articles two value usage only most layout effects data time more steps source code knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology NVidia Redmi vpn