Show TextView for an empty ListView inside a FrameLayout

前端 未结 4 1942
我寻月下人不归
我寻月下人不归 2021-01-28 09:18

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

4条回答
  •  没有蜡笔的小新
    2021-01-28 09:48

    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.

提交回复
热议问题