Android基础教程(十)之-------ListView的应用

大家好,终于可以又写blog了,前段时间准备日语,现在终于完了.我们今天要讲的内容是AndroidListView中的实现.一共分为四个步骤,我将一一讲解:

Step one:创建一个新的Android工程,命名为ListViewDemo.

Step two:找到ListViewDemo.java,把我们习惯的继承Activity,改成ListActivity,如下:

public class ListViewDemo extends ListActivity

Step three:修改ListViewDemo.java代码方法如下:

package com.example.listviewdemo;

import android.os.Bundle;
import android.app.ListActivity;
import android.widget.ArrayAdapter;

public class ListViewDemo extends ListActivity {  //此处用ListActivity而不是Activity
 
 static final String[] COUNTRIES = new String[]{
  "Americian","Belize","China","Japan","Korean","Russian"

 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        //
        setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,COUNTRIES));
    }
}

 

Step four:Run it(运行之)效果如下:

Android基础教程(十)之-------ListView的应用_第1张图片

你可能感兴趣的:(Android基础教程)