Android基礎教程(十)之-------ListView的應用

Step one:建立一個新的Android工程,命名爲ListViewDemo.

Step two:找到ListViewDemo.java,把咱們習慣的繼承Activity,改爲ListActivity,以下:

public class ListViewDemo extends ListActivity

Step three:修改ListViewDemo.java代碼方法以下:
java

  1. package com.android.test;

  2. import android.app.ListActivity;
  3. import android.os.Bundle;
  4. import android.widget.ArrayAdapter;

  5. public class ListViewDemo extends ListActivity {
  6. static final String[] COUNTRIES = new String[]{
  7.   "Americian","Belize","China","Japan","Korean","Russian"
  8. };
  9.     @Override
  10.     public void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.       setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1
  13.         ,COUNTRIES));
  14.     }
  15. }
複製代碼
Step four:Run it(運行之)效果以下:
相關文章
相關標籤/搜索