当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Add ListView content in an Activity

问题描述:

This question already has an answer here:

  • What is “android.R.layout.simple_list_item_1”?

    7 answers

网友答案:

Regarding your question, you have two options.

1) Something really simple that'll toString() your Item objects in each row.

ArrayAdapter<Item> adapter = new ArrayAdapter<Item>(
    MainActivity.this, // Context
    android.R.layout.simple_list_item_1, // An XML file for your items
    Item.items         // The Item[] array
);
listView.setAdapter(adapter);

2) Define your own adapter class with your own XML


If you know how to use ListActivity, you can still show other elements, by the way.

Read the documentation.

if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list"

分享给朋友:
您可能感兴趣的文章:
随机阅读: