what is android.R.layout.simple_list_item_1?

zcourts picture zcourts · May 21, 2011 · Viewed 32.4k times · Source

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();
}
}

Answer

Jake Wharton picture Jake Wharton · May 21, 2011

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"
/>