Android 在 ListView 中创建类别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1013765/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:35:53  来源:igfitidea点击:

Creating categories in a ListView?

androidlistviewcategories

提问by yanchenko

How do I create categories in an arbitrary ListView like those in Preferences (PreferenceCategory)?

如何在像 Preferences (PreferenceCategory) 中的那些任意 ListView 中创建类别?

I've found android.R.layout.preference_categorythat renders that grey TextView but don't see it mentioned anywhere from java code.

我发现android.R.layout.preference_category它呈现了灰色的 TextView,但在 java 代码中没有看到它提到的任何地方。

回答by yanchenko

How do I create categories in an arbitrary ListView like those in Preferences (PreferenceCategory)? I've found android.R.layout.preference_category that renders that grey TextView but don't see it mentioned anywhere from java code.

http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

Note that the code is from Android 0.9 and may require minor modifications to work in Android 1.5.

I have an Android 1.5-compatible variant on his code up at:

http://commonsware.com/AdvAndroid/

(scroll down, click on the Source Code link, and look at the ListView/Sections project)

-- Mark Murphy (a Commons Guy) http://commonsware.comThe Busy Coder's Guide to Android DevelopmentVersion 2.0 Available!

如何在像 Preferences (PreferenceCategory) 中的那些任意 ListView 中创建类别?我发现 android.R.layout.preference_category 呈现灰色 TextView 但没有看到它在 Java 代码中的任何地方提到。

http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

请注意,该代码来自 Android 0.9,可能需要稍作修改才能在 Android 1.5 中运行。

我在他的代码上有一个与 Android 1.5 兼容的变体:

http://commonsware.com/AdvAndroid/

(向下滚动,点击Source Code链接,查看ListView/Sections项目)

-- Mark Murphy(共享资源专家)http://commonsware.com忙碌的程序员指南 Android 开发2.0 版可用!

Thanks, Mark!

谢谢,马克!