Reading comments (0)
① When using listView or gridView, when the list is empty, sometimes a special empty view needs to be displayed to prompt the user. In general, If you inherit the ListActivity, as long
<ListView android: id = "@ id/android: list".../>
<TextView android: id = "@ id/android: empty.../>
TextView is automatically displayed when the list is empty.
 
②. If you inherit the Activity and want to see the above effect, you need to manually
<ListView android: id = "@ + id/list".../>
<TextView android: id = "@ + id/empty".../>
 
ListView list = (ListView) findViewById (R. id. mylist );
TextView TV = (TextView) findViewById (R. id. myempty );
 
List. setEmptyView (TV );
 
Misunderstanding:
SetEmptyView (View) is a misleading function, and sometimes EmptyView may be written in the code, as shown below:
 
TextView TV = new TextView (this );
TV. setText ("this is a empty view ")
SetEmptyView (TV );
This is not acceptable...
 
However, I said on a foreigner's Internet that this is feasible. Pay attention to lines 4 and 5:
 
[Java]
01. TextView emptyView = new TextView (context );
02. emptyView. setLayoutParams (new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. FILL_PARENT ));
03. emptyView. setText ("This appears when the list is empty ");
04. emptyView. setVisibility (View. GONE );
05. (ViewGroup) list. getParent (). addView (emptyView );
06. list. setEmptyView (emptyView );
TextView emptyView = new TextView (context );
EmptyView. setLayoutParams (new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. FILL_PARENT ));
EmptyView. setText ("This appears when the list is empty ");
EmptyView. setVisibility (View. GONE );
(ViewGroup) list. getParent (). addView (emptyView );
List. setEmptyView (emptyView );