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
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 inlistview
. Now we just bind the array list items to the row layout by usingmylistview.setadapter(aa)
;This is a part of the android OS. Here is the actual version of the defined XML file.
simple_list_item_1:
simple_list_item_2:
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.
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.
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.
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...