最简单的Android ListView(Android ListView example)

本例使用ArrayAdapter制作一个简单的list。

Main.java


package com.example.android_listview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class Main extends Activity{

private final static String[] str =
{"1111111111111111111111",
"2222222222222222222222",
"3333333333333333333333",
"4444444444444444444444",
"5555555555555555555555",
"6666666666666666666666",
"7777777777777777777777",
"8888888888888888888888",
"9999999999999999999999",
};

private ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  ArrayAdapter adapter = new ArrayAdapter(this,
  android.R.layout.simple_list_item_1, str);
  listView = (ListView)this.findViewById(R.id.list);

  listView.setAdapter(adapter);
}
}

main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>

</LinearLayout>

20140506_220802

 

JackSun

JackSun

I'm a coder.

You may also like...

Leave a Reply

Your email address will not be published.