Android 在模拟器上显示数据库中提取的信息的列表
2010-11-05 00:56:33 来源:WEB开发网时间有限,就不写注释了,看得懂的就看,看不懂的到晚上查资料
创建一个db的androiproject项目
同时创建一个MainActivity的Acitivity.java的类
新建com.gohighsoft.db包
MainActivity.java:
package com.gohighsoft.db;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private final static String TAG = "aa";
private PersonService personService;
private ListView listView;
// private PersonService personService;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
personService = new PersonService(this);// 前十条数据
List< Person> persons = personService.getScrollData(0, 100);
listView = (ListView) findViewById(R.id.personList);
List< HashMap< String, String>> data = new ArrayList< HashMap< String, String>>();
HashMap< String, String> title = new HashMap< String, String>();
title.put("personid", "编号");
title.put("name", "姓名");
title.put("age", "年龄");
data.add(title);
for (Person person : persons) {
HashMap< String, String> map = new HashMap< String, String>();
map.put("personid", String.valueOf(person.getId()));
map.put("name", person.getName());
map.put("age", String.valueOf(person.getAge()));
data.add(map);
}
更多精彩
赞助商链接