什么是" android.R.layout.simple_list_item_1"?android、QUOT、layout

2023-09-11 20:14:10 作者:你会变渺小¢

我已经开始学习Android开发和我从一本书下一个todolist的例子:

  //创建做项目的数组列表
最后的ArrayList<字符串> todoItems =新的ArrayList<字符串>();

//创建数组适配器将数组绑定到ListView
最后ArrayAdapter<字符串> AA;
AA =新的ArrayAdapter<字符串>(这一点,
                                android.R.layout.simple_list_item_1,
                                todoItems
                            );
myListView.setAdapter(AA);
 

我不明白这究竟code特别是这一行:

  android.R.layout.simple_list_item_1
 

解决方案

扎卡里亚,那就是引用一个内置的XML布局文件,它是Android操作系统的一部分,而不是你自己的XML布局中的一种。

Android FlexboxLayout 聪明的UI布局

下面是布局,您可以使用的详细列表: http://developer.android.com/reference/android/R.layout.html (更新链接感谢@Estel:https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout )

您可以实际查看code的布局。

I've started learning Android development and am following a todolist example from a book:

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

I can't understand exactly this code especially this line:

android.R.layout.simple_list_item_1

解决方案

Zakaria, that is a reference to an built-in XML layout document that is part of the Android OS, rather than one of your own XML layouts.

Here is a further list of layouts that you can use: http://developer.android.com/reference/android/R.layout.html (Updated link thanks @Estel: https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout )

You can actually view the code for the layouts.