Zak*_*ria 228 layout android android-arrayadapter
我已经开始学习Android开发了,并且正在遵循一本书中的一个todolist示例:
// Create the array list of to do items
final ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listView
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>( this,
android.R.layout.simple_list_item_1,
todoItems
);
myListView.setAdapter(aa);
Run Code Online (Sandbox Code Playgroud)
我无法理解这段代码特别是这一行:
android.R.layout.simple_list_item_1
Run Code Online (Sandbox Code Playgroud)
kco*_*ock 260
Zakaria,它是对作为Android OS一部分的内置XML布局文档的引用,而不是您自己的XML布局之一.
以下是您可以使用的更多布局列表:http:
//developer.android.com/reference/android/R.layout.html
(更新链接感谢@Estel:https://github.com/android/platform_frameworks_base/ tree/master/core/res/res/layout)
您实际上可以查看布局的代码.
nik*_*o28 35
这是Android操作系统的一部分.这是定义的XML文件的实际版本.
simple_list_item_1管理:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/listItemFirstLineStyle"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
simple_list_item_2:
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/listItemFirstLineStyle"/>
<TextView android:id="@android:id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
style="?android:attr/listItemSecondLineStyle" />
</TwoLineListItem>
Run Code Online (Sandbox Code Playgroud)
Nig*_*sto 13
如上所述:kcoppock和Joril
去这里:https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout
只需右键单击所需的布局文件,然后选择"另存为",保存到某处,然后将其复制到Android项目中的"布局"文件夹中(eclipse)...
你可以看看布局是怎么样的:)
要走的路......
如Klap所述"android.R.layout.simple_list_item_1是对作为Android OS一部分的内置XML布局文档的引用"
所有布局都位于:sdk\platforms\android-xx\data\res\layout
要查看布局的XML:
Eclipse:只需在代码中的某处键入android.R.layout.simple_list_item_1,按住Ctrl键,将鼠标悬停在simple_list_item_1上,然后从出现的下拉列表中选择"在layout/simple_list_item_1.xml中打开声明".它将引导您访问XML的内容.
Android Studio:项目窗口 - >外部库 - > Android X平台 - > res - >布局,在这里您将看到可用布局列表.

小智 7
android.R.layout.simple_list_item_1,这是res/layout文件夹中的行布局文件,其中包含行的相应设计listview.现在我们通过使用将数组列表项绑定到行布局mylistview.setadapter(aa);
无需转到外部链接,您需要的所有内容都已存在于您的计算机上:
Android的\ Android的SDK \平台\ Android的-X\DATA \水库\布局.
所有Android布局的源代码都位于此处.
Per Arvand:
Eclipse:只需在代码中的某处键入android.R.layout.simple_list_item_1,按住 Ctrl,将鼠标悬停在simple_list_item_1 上,然后从出现的下拉列表中选择Open Declaration in layout/simple_list_item_1.xml。它将引导您访问 XML 的内容。
从那里,如果您将鼠标悬停在编辑器中生成的simple_list_item_1.xml选项卡上,您将看到该文件位于C:\Data\applications\Android\android-sdk\platforms\android-19\data\res\ layout\simple_list_item_1.xml(或安装的等效位置)。