热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用ListView在Android中创建一个设置屏幕?-UsingaListViewtocreateasettingsscreeninAndroid?

ImdevelopingmyfirstAndroidapplication,andIdliketocreateasettingsscreen.我正在开发我的第一个An

I'm developing my first Android application, and I'd like to create a settings screen.

我正在开发我的第一个Android应用程序,我想创建一个设置屏幕。

I'd like the screen to have a similar look-and-feel as the native phone-settings screens and the native "create/edit alarm" screen. Thus with different kinds of (statically defined) items vertically stacked with a thin line between them.

我希望屏幕具有与本机手机设置屏幕和本机“创建/编辑警报”屏幕类似的外观和感觉。因此,不同种类的(静态定义的)物品垂直地堆放在它们之间的一条细线上。

How do I define such screen?

如何定义这样的屏幕?

I understand I can use the ListView, but this seems to be primarily meant for serving dynamic data using a ListAdapter, where each item is served in the same format. It seems to be possible to create different items (that is, some with checkbox, some with two text-lines, some with an icon) by creating my own ListAdapter and overriding getView but this seems like overkill. Should I be using a ListView for this purpose?

我知道我可以使用ListView,但这似乎主要是为了使用ListAdapter来服务动态数据,每个条目都以相同的格式提供服务。通过创建自己的ListAdapter并覆盖getView,似乎可以创建不同的项(即,有些带有复选框,有些带有两个文本行,有些带有图标),但这似乎有些过头了。为此,我应该使用ListView吗?

2 个解决方案

#1


121  

There's no need to manually create and format a ListView - there are ways in the API to create Preference screens.

无需手动创建和格式化ListView——在API中有创建首选项屏幕的方法。

The most obvious is PreferenceActivity.

最明显的是偏好活动。

You can define all your preferences in an XML file, a bit like a layout, and then load them with addPreferencesFromResource() or you can create a number of PreferenceScreen objects in code and populate them with Preference objects that way.

您可以在XML文件中定义所有首选项,有点像布局,然后使用addPreferencesFromResource()加载它们,或者您可以在代码中创建许多PreferenceScreen对象,并用首选项对象填充它们。

The best thing do would be to look at the API Demos application provided with the Android API. This contains lots of good examples of managing preferences. Here's how it creates preferences from code and here's a sample preferences XML file. There are other examples showing more advanced things like preference dependencies and preference listeners.

最好的做法是查看Android API提供的API演示应用程序。这包含了许多管理首选项的好例子。下面是它如何从代码创建首选项,下面是一个示例首选项XML文件。还有一些例子显示了更高级的东西,比如偏好依赖项和偏好侦听器。

#2


2  

Actually in the built-in alarm application, for edit and create alarms, there are two activities, one for create and one for edit.

实际上,在内置的警报应用程序中,对于编辑和创建警报,有两个活动,一个用于创建,一个用于编辑。

The Create Alarm activity is the first one with the digital clock. The Edit Alarm activity is started by clicking on a listed alarm from the Create Alarm activity.

创建闹钟活动是第一个带有数字时钟的活动。编辑警报活动是通过单击创建警报活动中的列出的警报启动的。

Edit Alarm implements PreferenceActivity, but Create Alarm is more complex (custom cursor adapter to list the alarms).

编辑警报实现PreferenceActivity,但是创建警报更复杂(自定义游标适配器列出警报)。

Have a look at the sources:

看一下资料来源:

  • Create Alarm activity
  • 创建警报活动
  • Edit Alarm activity
  • 编辑报警活动

推荐阅读
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • Android自定义控件绘图篇之Paint函数大汇总
    本文介绍了Android自定义控件绘图篇中的Paint函数大汇总,包括重置画笔、设置颜色、设置透明度、设置样式、设置宽度、设置抗锯齿等功能。通过学习这些函数,可以更好地掌握Paint的用法。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • 本文介绍了OpenStack的逻辑概念以及其构成简介,包括了软件开源项目、基础设施资源管理平台、三大核心组件等内容。同时还介绍了Horizon(UI模块)等相关信息。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • 本文介绍了Python语言程序设计中文件和数据格式化的操作,包括使用np.savetext保存文本文件,对文本文件和二进制文件进行统一的操作步骤,以及使用Numpy模块进行数据可视化编程的指南。同时还提供了一些关于Python的测试题。 ... [详细]
  • 本文介绍了利用ARMA模型对平稳非白噪声序列进行建模的步骤及代码实现。首先对观察值序列进行样本自相关系数和样本偏自相关系数的计算,然后根据这些系数的性质选择适当的ARMA模型进行拟合,并估计模型中的位置参数。接着进行模型的有效性检验,如果不通过则重新选择模型再拟合,如果通过则进行模型优化。最后利用拟合模型预测序列的未来走势。文章还介绍了绘制时序图、平稳性检验、白噪声检验、确定ARMA阶数和预测未来走势的代码实现。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了Windows操作系统的版本及其特点,包括Windows 7系统的6个版本:Starter、Home Basic、Home Premium、Professional、Enterprise、Ultimate。Windows操作系统是微软公司研发的一套操作系统,具有人机操作性优异、支持的应用软件较多、对硬件支持良好等优点。Windows 7 Starter是功能最少的版本,缺乏Aero特效功能,没有64位支持,最初设计不能同时运行三个以上应用程序。 ... [详细]
  • Introduction(简介)Forbeingapowerfulobject-orientedprogramminglanguage,Cisuseda ... [详细]
author-avatar
GGG-敏
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有