您的位置:首页 > 移动开发 > Objective-C

SimpleAdapter 和 SimpleCursorAdapter的使用

2010-06-27 17:19 274 查看
 

 

 

SimpleAdapter

ArrayList<HashMap<String,Object>> arr =
new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("image", R.drawable.icon);
map.put("text","杨锐");
arr.add(map);

map = new HashMap<String,Object>();
map.put("image", R.drawable.icon);
map.put("text","谢剑");
arr.add(map);

map = new HashMap<String,Object>();
map.put("image", R.drawable.icon);
map.put("text","李晨");
arr.add(map);

map = new HashMap<String,Object>();
map.put("image", R.drawable.icon);
map.put("text","郑慧东");
arr.add(map);

SimpleAdapter sla = new SimpleAdapter(this,arr,R.layout.layout22,
new String[]{"image","text"},
new int[]{R.id.iv,R.id.tv});

SimpleCursorAdapter sca =
new SimpleCursorAdapter(
this,R.layout.layout22,cursor,
new String[]{"_id","username","phone","types","nowtime"},
new int[]{R.id.tv,R.id.tv1,R.id.tv2,R.id.tv3,R.id.tv4});
 

 

SimpleCursorAdapter

protected Cursor getList() {
Cursor cursor = null;
sqlbase = this.getReadableDatabase();
try {
cursor = sqlbase.query(tableName, new String[]{"_id"},null,null,null,null,null);
cursor.getCount();
} catch (SQLiteException e) {
Log.e("!!!!!!", "getList ERROR");
closeCon();
}
closeCon();
return cursor;
}

Cursor cursor = db.getList();
SimpleCursorAdapter sca =
new SimpleCursorAdapter(
this,R.layout.layout22,cursor,
new String[]{"_id"},
new int[]{R.id.tv});
ListView lv = (ListView) findViewById(R.id.listv);
lv.setAdapter(sca);
break;
 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息