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进行数据绑定显示列表。

  • 相关阅读:
    P3 创建项目(下)
    P2 创建项目(中)
    P1 创建项目(上)
    ASP.NET Core 3.x 入门视频(完结)
    网易云微专业《职场人必学的Python技能课》
    01.Python配置与运行
    阶段一-03.地址,订单,支付,定时任务开发-第1章 收货地址功能开发-1-6 收货地址
    ASYNC PROGRAMING IN JAVASCRIPT[转]
    Bluebird-NodeJs的Promise
    理解Nodejs的Event Loop
  • 原文地址:https://www.cnblogs.com/harry335/p/4796427.html
Copyright © 2011-2022 走看看