Step one:建立一個新的Android工程,命名爲ListViewDemo.
Step two:找到ListViewDemo.java,把咱們習慣的繼承Activity,改爲ListActivity,以下:
public class ListViewDemo extends ListActivity
Step three:修改ListViewDemo.java代碼方法以下: java
- package com.android.test;
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- public class ListViewDemo extends ListActivity {
- static final String[] COUNTRIES = new String[]{
- "Americian","Belize","China","Japan","Korean","Russian"
- };
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1
- ,COUNTRIES));
- }
- }
複製代碼
Step four:Run it(運行之)效果以下: