Reputation: 10777
I am new to android and i am confused about something. I have created a simple ListView, here is my code:
public class MainActivity extends ListActivity {
ArrayList<String> listItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listItems = new ArrayList<String>();
for(int i=0;i<20;i++){
listItems.add("List Item #"+i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
}
}
This correctly displays the list items on the screen, but here is my question: I have no xml files, no layouts in my project and i do not use setContentView function here. So why is this code working? How can it be displayed even though there is no xml files or layouts?
Thanks
Upvotes: 1
Views: 42
Reputation: 13474
Android ships with default containers for list items.
As the name suggests, android.R.layout.simple_list_item_1
belongs to the android.R package and not to your app's resources.
Upvotes: 2
Reputation: 67239
You are using android.R.layout.simple_list_item_1
as the layout, which provides a TextView
for you to work with. This is a layout provided by Android for simple lists of text.
If you want to make a more complex layout, you will/can define your own layout.
Upvotes: 3