Android 在模拟器上显示数据库中提取的信息的列表
2010-11-05 00:56:33 来源:WEB开发网Cursor cursor = db.rawQuery("select count(*) from person", null);
// 没有占位符参数的话,直接用null
cursor.moveToFirst();
Long count = cursor.getLong(0);
cursor.close();
return count;
}
}
实体类传递数据:Person.java
package com.gohighsoft.db;
public class Person {
private Integer id;
private String name;
private Integer age;
public Person() {
};
public Person(String name, Integer age) {
this.name = name;
this.age = age;
}
public Integer getId(){
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String toString() {
return "Person [age=" + age + ",id=" + id + ",name" + name + "]";
}
}
最后main.xml:
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
< ListView android:id="@+id/personList" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
< /LinearLayout>
好了到此为止算是完成了,直接运行MainActivity.java就可以了
看不懂的自己上网去查去,不再详细的解释了.
更多精彩
赞助商链接