如何在空时显示 ListView 的标题 [英] How to show header of ListView when its empty

查看:16
本文介绍了如何在空时显示 ListView 的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发以下屏幕

彼此相邻的四个框是按钮.单击按钮时,我正在更改列表视图的适配器.

The fourboxes next to each other are buttons. On clicking of the buttons I am changing the adapter of the listview.

由于列表视图上方的内容占用了大量空间,我将整个内容作为标题并通过代码添加.

Since the content above the listview took up lot of space I made the whole thing as an header and added it via code.

   myPollsList = (ListView) findViewById(R.id.listArea);
myPollsList.addHeaderView(getLayoutInflater().inflate(R.layout.profile_listview_header, null));

现在我想在列表为空时显示一些视图.但如果我这样做,标题也会消失.

Now I want to show some view when the list is empty. But if I do that then the header also goes away.

我在 Activity 而不是 ListActivity 中使用它.即使列表为空也有显示标题的建议或解决方法吗?

I am using this in a Activity and not a ListActivity. Any suggestions or workarounds for showing the header even when the list is empty ?

参考我之前的问题 ListView没有空间在较小的屏幕上显示内容.这是有人建议我通过将其作为标题来解决问题的地方

Refer to my earlier question here ListView not getting space to show content on smaller screens . This is where someone suggested me to solve the problem by putting it as a header

推荐答案

所以我就是这样解决的.我有一个连接到列表视图的自定义适配器.当它发现它有零个项目要显示时.它会将一个虚假的空视图作为项目添加到列表中.

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.

这篇关于如何在空时显示 ListView 的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆