什么是android.R.layout.simple_list_item_1? [英] what is android.R.layout.simple_list_item_1?

查看:240
本文介绍了什么是android.R.layout.simple_list_item_1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有我见过他们创建一个ArrayAdapter时,只需使用android.R.layout.simple_list_item_1的例子。 什么是android.R.layout.simple_list_item_1,它是一个布局文件名为simple_list_item_1.xml的只是名字或者是它的TextView的所需阵列适配器的ID?

我如何能看到文件的内容,或者使用自己的文件从我的res文件夹?

 公共类MyClass的扩展ListActivity {
私有String []标题= {测试};

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.mylayout);

    setListAdapter(新ArrayAdapter<字符串>(这一点,
            android.R.layout.simple_list_item_1,职称));
     updateList();
}
}
 

解决方案

android.R.layout 包含了所有的Andr​​oid操作系统用于显示各种公开可用布局项目。 android.R.layout.simple_list_item_1 ,正如它的命名,只是一个简单的布局,显示的文字片段。它使您无需使用适配器时,写简单的布局,也能提供您以最小的努力你的应用程序中的本机外观和系统的主题。

我已经包含在源<一href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_list_item_1.xml">from在 android.git.kernel.org 的GitHub的镜子回购

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;  - !版权所有(C)2006年的Andr​​oid开源项目

     Apache许可证下授权,版本2.0(以下简称许可证);
     你可能不使用这个文件除了在遵守许可。
     您可以在获得许可证的副本

          http://www.apache.org/licenses/LICENSE-2.0

     除非适用法律要求或书面同意,软件
     该许可证下发布分布在原样的基础上,
     无担保或任何形式的条件,无论是EX preSS或暗示的保证。
     查看许可证的特定语言的管理权限和
     该许可证下的限制。
 - &GT;

&LT; TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / text1中
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceLarge
    机器人:重力=center_vertical
    机器人:以下属性来=6dip
    机器人:=了minHeight机器人:ATTR /列表preferredItemHeight
/&GT;
 

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

解决方案

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

这篇关于什么是android.R.layout.simple_list_item_1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆