在我看到的所有示例中,它们在创建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(); } }
android.R.layout包含Android操作系统用来显示各种项目的所有公共可用布局。android.R.layout.simple_list_item_1顾名思义,它只是一个显示文本片段的简单布局。它使您免于在使用适配器时不必编写简单的布局,并且使您在应用程序中的系统本机外观和主题花费了最少的精力。
android.R.layout
android.R.layout.simple_list_item_1
我已经包括了来自android.git.kernel.org回购的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" />