开发者

what is android.R.layout.simple_list_item_1?

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 adapt开发者_如何学Goer?

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


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


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

what is android.R.layout.simple_list_item_1?

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


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜