Android ListView详解(6)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:34 点击:次
public List<Person> getAllPersons(){
String sql = "select name,age from person";
Cursor cursor = sqLiteDatabase.rawQuery(sql, null);
Person person = null;
List<Person> personList = new ArrayList<Person>();
while(cursor.moveToNext()){
String name = cursor.getString(0);
int age = cursor.getInt(1);
person = new Person(name,age);
personList.add(person);
}
return personList;
}
//分页取数据
public List<Person> getScrollData(Integer start, Integer size){
String sql = "select personid, name,age from person limit ?,?";
Cursor cursor = sqLiteDatabase.rawQuery(sql, new String[]{String.valueOf(start),String.valueOf(size)});
List<Person> personList = new ArrayList<Person>();
Person person = null;
while(cursor.moveToNext()){
int personid = cursor.getInt(0);
String name = cursor.getString(1);
int age = cursor.getInt(2);
person = new Person(name,age);
person.setPersonid(personid);
personList.add(person);
}
return personList;
}
//返回游标对象,当要在ListView中显示数据时,主键的字段名需设定为_id,否则返回的Cursor对象会出错
public Cursor getRawScrollData(Integer start, Integer size){
String sql = "select personid as _id, name,age from person limit ?,?";
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>