如何设置这样的 ListView 背景。 我想在记录数为0时出现
最佳答案
ListView
中有特殊方法 - setEmptyView()
.您可以找到使用它的示例 here或 here .
更新:第二个链接现在不可用。这是文章的引述:
When you set a ListView’s “empty view” programmatically, you can end up scratching your head as to why your empty view actually doesn’t appear when the list is empty.
If this happens, then what you forgot is that you must manually add your empty view to your view hierarchy, cos ListView won’t do it for you. Although it’s obvious when you think about it, the documentation doesn’t mention this detail, and Googling shows at least one person had the problem.Here’s the code with the lines that it’s all too easy to forget at numbers 4 and 5…
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);
关于android - 如何设置一个空的 ListView 的背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6251109/