zoukankan      html  css  js  c++  java
  • 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进行数据绑定显示列表。

  • 相关阅读:
    react路由组件&&非路由组件
    react函数式组件(非路由组件)实现路由跳转
    react使用antd组件递归实现左侧菜单导航树
    【LeetCode】65. Valid Number
    【LeetCode】66. Plus One (2 solutions)
    【LeetCode】68. Text Justification
    【LeetCode】69. Sqrt(x) (2 solutions)
    【LeetCode】72. Edit Distance
    【LeetCode】73. Set Matrix Zeroes (2 solutions)
    【LeetCode】76. Minimum Window Substring
  • 原文地址:https://www.cnblogs.com/harry335/p/4796427.html
Copyright © 2011-2022 走看看