什么是android.R.layout.simple_list_item_1?

zco*_*rts 10 java android listview android-arrayadapter

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

Jak*_*ton 29

android.R.layout包含Android OS用于显示各种项目的所有公开可用布局.android.R.layout.simple_list_item_1就像它的名字一样,只是一个简单的布局来显示一段文字.它使您无需在使用适配器时编写简单的布局,还可以轻松地为应用程序提供系统的本机外观和主题.

我已经android.git.kernel.org repo 的GitHub镜像中包含了源代码

<?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"
/>
Run Code Online (Sandbox Code Playgroud)