Android学习笔记-ListView
2010-10-13 01:57:00 来源:本站整理今天主要是学习了ListView控件。先把代码粘一下。
package com.eoeAndroid.list;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class ActivityList2 extends Activity {
private List< Map< String, Object>> data;
private ListView listView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PrepareData();
listView = new ListView(this);
// 利用系统的layout显示一项
// SimpleAdapter adapter = new SimpleAdapter(this, data,
// android.R.layout.simple_list_item_1, new String[] { "姓名" },
// new int[] { android.R.id.text1 });
// 利用系统的layout显示两项
SimpleAdapter adapter = new SimpleAdapter(this, data,
android.R.layout.simple_list_item_2, new String[] { "姓名","性别" },
new int[] { android.R.id.text1 , android.R.id.text2});
// 利用自己的layout来进行显示两项
// SimpleAdapter adapter = new SimpleAdapter(this, data,
// R.layout.list_item, new String[] { "姓名", "性别" }, new int[] {
// R.id.mview1, R.id.mview2 });
listView.setAdapter(adapter);
setContentView(listView);
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView< ?> parent, View view, int position,
long id) {
setTitle(parent.getItemAtPosition(position).toString());
更多精彩
赞助商链接