android.R.layout.simple_list_item_1是什么?

发布于 2024-11-08 23:41:42 字数 600 浏览 0 评论 0原文

在我看到的所有示例中,他们在创建 ArrayAdapter 时仅使用“android.R.layout.simple_list_item_1”。 android.R.layout.simple_list_item_1是什么,它只是一个名为simple_list_item_1.xml的布局文件的名称还是数组适配器所需的TextView的id?

如何查看文件的内容或使用 res 文件夹中我自己的文件?

public class MyClass extends ListActivity {
private String[] titles = {"Test"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mylayout);

    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, titles));
     updateList();
}
}

In all the examples I've seen they just use "android.R.layout.simple_list_item_1" when creating an ArrayAdapter.
What is android.R.layout.simple_list_item_1,Is it just the name of a layout file called simple_list_item_1.xml or is it the id of the TextView required for the array adapter?

How do I see the content of the file or use my own file from my res folder?

public class MyClass extends ListActivity {
private String[] titles = {"Test"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mylayout);

    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, titles));
     updateList();
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掐死时间 2024-11-15 23:41:42

android.R.layout 包含 Android 操作系统用于显示各种项目的所有公开可用的布局。 android.R.layout.simple_list_item_1 正如其名称所示,只是一个用于显示文本片段的简单布局。它使您不必在使用适配器时编写简单的布局,并且还可以轻松地在应用程序中为您提供系统的本机外观和主题。

我已经包含了来自 GitHub 镜像的源代码android.git.kernel.org 存储库的 a>

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>

android.R.layout contains all of the publicly available layouts that the Android OS uses to display various items. android.R.layout.simple_list_item_1 is, as it's named, just a simple layout to display a snippet of text. It saves you from having to write simple layouts when using adapters and also affords you the native look and theme of the system in your application with minimal effort.

I have included the source from the GitHub mirror of the android.git.kernel.org repo

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>
鸠魁 2024-11-15 23:41:42

Android API 中有一些内置布局 XML 文件
此图像中列出了

在此处输入图像描述

android.R.layout.simple_list_item_1 就是其中之一
它用于简单显示字符串

您可以使用您自己的布局而不是 android.R.layout.simple_list_item_1

例如如果您已经制作了布局 row.xml 那么您可以使用 as

setListAdapter(new ArrayAdapter<String>(this, R.layout.row, titles));

There are some Inbuilt Layout XML files in Android API
and there are listed in this Image

enter image description here

android.R.layout.simple_list_item_1 is one of them
it is use for simple display of String

You can use Your Own Layout instead of android.R.layout.simple_list_item_1

for example If you have made a layout row.xml then you can use as

setListAdapter(new ArrayAdapter<String>(this, R.layout.row, titles));
憧憬巴黎街头的黎明 2024-11-15 23:41:42

android.R.layout.simple_list_item_1 是一个内置布局资源,它显示单个字符串。
如果你想使用自己的布局文件,那么你可以使用

setListAdapter(new ArrayAdapter<String>(this, R.layout.<your layout filename>, titles));

The android.R.layout.simple_list_item_1 is an inbuilt layout resource and it displays a single string.
If you want to use your own layout file then you can use

setListAdapter(new ArrayAdapter<String>(this, R.layout.<your layout filename>, titles));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文