I have a tabbed layout and an activity using tabs as views. It has three tabs as ListViews
. If either of the lists is empty I want to show a simple TextView>
Just call setEmptyView(...) on your ListView
, passing in the TextView
as argument.
TextView empty = (TextView) findViewById(R.id.blank);
mListView_top10.setEmptyView(empty);
The ListView
should automatically take care of toggling the visibility of the 'empty' view.
Tip: since the argument is a generic View
, you can pass in any subclass of View
, or more complex view hierarchy.
On a side note: you will probably have to give each ListView
its own TextView
instance as empty view to avoid clashing scenarios; e.g. when one list does have content, while another doesn't.