用一个ListView创建于Android的一个设置屏幕?屏幕、创建于、ListView、Android

2023-09-05 05:23:47 作者:结局却一个人

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

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

我想在屏幕上有一个类似的外观和感觉作为本地电话设置屏幕和本机创建/编辑报警画面。因此,与不同种类的(静态定义)项垂直堆叠在它们之间的细线。

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?

我明白我可以使用ListView控件,但这似乎主要是为了使用ListAdapter,每个项目都提供相同的格式提供的动态数据。这似乎是可以创建不同的项(也就是一些使用复选框,一些带有两个文本线,有的用一个图标),通过创建自己的ListAdapter和压倒一切的getView但这似乎是大材小用。我应该使用一个ListView用于此目的?

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 - 有办法在API中创建preference屏幕。

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

最明显的是$p$pferenceActivity.

您可以定义所有的preferences在XML文件中,有点像一个布局,然后加载它们与add$p$pferencesFromResource()或者你可以创建多个$p$pferenceScreen在code对象并填充它们与$p$pference对象的方式。

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.

最好的事情确实是看提供了Android API的API演示应用程序。这包含了大量的管理preferences很好的例子。这里的how它创建从code preferences和这里的样品preferences XML文件。有显示类似preference依赖性和preference听众更先进的东西,其他的例子。

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.