How to show header of ListView when its empty

一世执手 提交于 2019-11-28 11:33:57

I found a simple solution for this problem. If there's no elements for list and you are not adding the adapter, just add this:

mListView.setAdapter(null);

and the header will appear. It's easier than adding empty / fake item to the list.

So this is how I solved it. I had a custom adapter which was connected to the listview. When it found that it had zero items to display. It would add a fake empty view as an item to the list.

maybe you will like this Android addHeaderView disappears when no items in ListView

override/subclass your adapter to return false from isEmpty()

Don't use top layouts of button as header for list view.

So to adjust UI without using list header use weights.

Give parent Linear layout weight sum as 4 and 1, 1 to top Layouts and 2 for list view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!