Android采用ListView实现数据列表显示2-使用SimpleAdapter进行数据绑定

Android采用ListView实现数据列表显示2-使用SimpleAdapter进行数据绑定

和前面的相比需要获得

  1. //获取到集合数据  
  2.         List<Person> persons = service.getScrollData(0, 10);  
  3.         List<HashMap<String, Object>> data = new ArrayList<HashMap<String,Object>>();

但一般查询出来cursor的情况多一些,下面是cursor转换成List<Person>的例子。

  1. public List<Person> getAllPersons() {  
  2.         String sql = "select * from person";  
  3.         SQLiteDatabase db = helper.getWritableDatabase();  
  4.         List<Person> personList = new ArrayList<Person>();  
  5.         Person personnull;  
  6.         Cursor cursor = db.rawQuery(sql, null);  
  7.         while (cursor.moveToNext()) {  
  8.             personnew Person();  
  9.             person.setId()(cursor.getString(cursor  
  10.                     .getColumnIndex("id")));  
  11.             person.setName()(cursor.getDouble(cursor  
  12.                     .getColumnIndex("name")));  
  13.             person.setPhone()(cursor.getDouble(cursor  
  14.                     .getColumnIndex("phone")));  
  15.             person.setAmount(cursor.getDouble(cursor.getColumnIndex("amount")));
  16.             personList .add(person);  
  17.         }  
  18.         return personList;  
  19.     } 

有了List<Person>集合数据剩下的可以使用使用SimpleAdapter进行数据绑定显示列表。

原文地址:https://www.cnblogs.com/harry335/p/4796427.html