Android ListView 标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1966802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android ListView Headers
提问by Jeremy Edwards
How do you make those standard header labels in the ListView Control?
你如何在 ListView 控件中制作那些标准的标题标签?
An example would be in the contacts application you see the first letter of the grouped contacts for each letter in the alphabet.
例如,在联系人应用程序中,您会看到字母表中每个字母的分组联系人的第一个字母。
If possible please provide some code snippets on how to construct the grouped data and the display of the ListView.
如果可能,请提供一些关于如何构建分组数据和 ListView 显示的代码片段。
采纳答案by CommonsWare
You can use my MergeAdapter
or Jeff Sharkey's SeparatedListAdapter
for that.
你可以使用我的MergeAdapter
或杰夫夏基的SeparatedListAdapter
。
In the case of MergeAdapter
, you would add an ordinary View
(e.g., TextView
) for a section header, then an Adapter
for the contents of that section. Lather, rinse, repeat.
在 的情况下MergeAdapter
,您将为节标题添加一个普通的View
(例如,TextView
),然后Adapter
为该节的内容添加一个。起泡,冲洗,重复。