是什么android.R.layout.simple_list_item_1和android.R.layout.simple_list_item_2之间的区别 [英] What is difference between android.R.layout.simple_list_item_1 and android.R.layout.simple_list_item_2
问题描述
谁能解释android.R.layout.simple_list_item_1和android.R.layout.simple_list_item_2在arrayadapter的机器人。
Can anyone explain android.R.layout.simple_list_item_1 and android.R.layout.simple_list_item_2 in arrayadapter in android.
我知道android.R.layout.simple_list_item_1和android.R.layout.simple_list_item_2是布局是定义机器人本身。
I know in android.R.layout.simple_list_item_1 and android.R.layout.simple_list_item_2 are layout which is define in android itself.
在android.R.layout.simple_list_item_1只只包含一个TextView的,但android.R.layout.simple_list_item_2包含两个文本视图。
in android.R.layout.simple_list_item_1 only contain only one textview but android.R.layout.simple_list_item_2 contain two text view.
我想例子android.R.layout.simple_list_item_2 ...如何显示在列表视图与适配器两个文本视图。
i want to example for android.R.layout.simple_list_item_2 ...how to show two text view in listview with adapter.
我的code是
package com.app.listview;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ExampleListViewActivity extends Activity {
private String[] nameArr = new String[]{"Arun","Anil","Ankit","Manoj"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView)findViewById(R.id.lv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1,
nameArr);
listView.setAdapter(adapter);
}
}
推荐答案
不同的是以下内容。 simple_list_item_1管理
仅包含一个的TextView
,而 simple_list_item_2
有两个内 RelativeLayout的
的子类。这些都取自果冻豆。
The difference is the following. simple_list_item_1
contains only a TextView
, whereas simple_list_item_2
has two inside a subclass of RelativeLayout
. These are both taken from Jelly Bean.
simple_list_item_1管理
<?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/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
/>
simple_list_item_2
<?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.
-->
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:mode="twoLine"
>
<TextView android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft"
android:layout_marginTop="8dip"
android:textAppearance="?android:attr/textAppearanceListItem"
/>
<TextView android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
android:layout_alignLeft="@android:id/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</TwoLineListItem>
按照文档的ArrayAdapter :
在默认情况下此类预期所提供的资源ID引用 一个TextView的。
By default this class expects that the provided resource id references a single TextView.
所以在默认情况下,一个 ArrayAdapter
不自动填入多个的TextView
实例。你可以,但是,覆盖 getView()
的方法,并利用两个的TextView
s表示出现在 R.layout.simple_list_item_2
So by default, an ArrayAdapter
doesn't automatically fill in multiple TextView
instances. You can, however, override the getView()
method and fill in the two TextView
s that appear in R.layout.simple_list_item_2
这篇关于是什么android.R.layout.simple_list_item_1和android.R.layout.simple_list_item_2之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!