Reputation: 15070
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
Upvotes: 243
Views: 256322
Reputation: 1040
I know this question has been answered.
Searching for this layout I wanted to see what this layout and others look like, so I decided to provide the appearances of your questioned layout and others.
Based on @Kevin Coppock's answer I picked some list item layouts.
All theses layouts are in the standard set of Android:
Upvotes: 0
Reputation: 111
android.R.layout.simple_list_item_1
, this is row layout file in your res/layout folder which contains the corresponding design for your row in listview
. Now we just bind the array list items to the row layout by using mylistview.setadapter(aa)
;
Upvotes: 8
Reputation: 2971
This is a part of the android OS. Here is the actual version of the defined XML file.
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" />
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>
Upvotes: 37
Reputation: 1105
Per Arvand:
Eclipse: Simply type android.R.layout.simple_list_item_1 somewhere in code, hold Ctrl, hover over simple_list_item_1, and from the dropdown that appears select Open declaration in layout/simple_list_item_1.xml. It'll direct you to the contents of the XML.
From there, if you then hover over the resulting simple_list_item_1.xml tab in the Editor, you'll see the file is located at C:\Data\applications\Android\android-sdk\platforms\android-19\data\res\layout\simple_list_item_1.xml (or equivalent location for your installation).
Upvotes: 5
Reputation: 5720
As mentioned by Klap "android.R.layout.simple_list_item_1 is a reference to an built-in XML layout document that is part of the Android OS"
All the layouts are located in: sdk\platforms\android-xx\data\res\layout
To view the XML of layout :
Eclipse: Simply type android.R.layout.simple_list_item_1 somewhere in code, hold Ctrl, hover over simple_list_item_1, and from the dropdown that appears select "Open declaration in layout/simple_list_item_1.xml". It'll direct you to the contents of the XML.
Android Studio: Project Window -> External Libraries -> Android X Platform -> res -> layout, and here you will see a list of available layouts.
Upvotes: 9
Reputation: 243
No need to go to external links, everything you need is located on your computer already:
Android\android-sdk\platforms\android-x\data\res\layout.
Source code for all android layouts are located here.
Upvotes: 5
Reputation: 134714
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.
Upvotes: 270
Reputation: 314
as answered above by: kcoppock and Joril
go here : https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout
just right click the layout file you want, then select 'Save As', save somewhere, then copy it in 'layout' folder in your android project(eclipse)...
you can see how the layout looks like :)
way to go...
Upvotes: 13