什么是 android.R.layout.simple_list_item_1?

Posted

技术标签:

【中文标题】什么是 android.R.layout.simple_list_item_1?【英文标题】:what is android.R.layout.simple_list_item_1? 【发布时间】:2011-08-30 01:51:02 【问题描述】:

在我看到的所有示例中,他们在创建 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();


【问题讨论】:

***.com/questions/3663745/… 的副本 【参考方案1】:

android.R.layout 包含 Android 操作系统用于显示各种项目的所有公开可用的布局。 android.R.layout.simple_list_item_1 就像它的名字一样,只是一个简单的布局,用于显示文本的 sn-p。它使您不必在使用适配器时编写简单的布局,还可以在您的应用程序中以最小的努力为您提供系统的原生外观和主题。

我已经包含了android.git.kernel.org repo 的来源from the GitHub mirror

<?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_
    android:layout_
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>

【讨论】:

感谢您的信息,我知道 R.layout.file 代表什么我只是不知道它们与所有机器人一起分发,出于某种原因,我认为这是来自 API 的示例布局演示 这段代码其实就是simple_list_item_1.xml。仅包含一个 TextView 的布局文件。【参考方案2】:

Android API 中有一些 Inbuilt Layout XML 文件 并且在这张图片中列出了

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

您可以使用 Your Own Layout 而不是 android.R.layout.simple_list_item_1

例如如果你做了一个布局row.xml那么你可以使用as

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

【讨论】:

【参考方案3】:

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

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

【讨论】:

以上是关于什么是 android.R.layout.simple_list_item_1?的主要内容,如果未能解决你的问题,请参考以下文章

时间是什么?时间同步是什么?GPS北斗卫星授时又是什么?

什么是拉电流,什么是灌电流?什么是吸收电流 ?

在java中,OOA是什么?OOD是什么?OOP是什么?

什么是DIV,全称是什么?

什么是抢占/什么是可抢占内核?到底有什么好处呢?

什么是 JNDI?它的基本用途是什么?什么时候使用?