用SQLite记录数据后。用listview显示为什么所有行都显示为最后一次输入的数据?
privateList<Map<String,Object>>getDate(){List<Map<String,Object>>list=newArrayList<Ma...
private List<Map<String,Object>> getDate(){
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
Map<String,Object> map=new HashMap<String,Object>();
String sql="select*from items_list";
try{
db=dabaseHelper.getWritableDatabase();
Cursor cursor=db.rawQuery(sql, null);
while(cursor.moveToNext()){
String title=cursor.getString(1);
String details=cursor.getString(2);
String time=cursor.getString(3);
map.put("title",title);
map.put("info",time);
map.put("img",R.drawable.dog1);
list.add(map);
}
cursor.close();
db.close();
}
catch(Exception exp){}
return list;
} 展开
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
Map<String,Object> map=new HashMap<String,Object>();
String sql="select*from items_list";
try{
db=dabaseHelper.getWritableDatabase();
Cursor cursor=db.rawQuery(sql, null);
while(cursor.moveToNext()){
String title=cursor.getString(1);
String details=cursor.getString(2);
String time=cursor.getString(3);
map.put("title",title);
map.put("info",time);
map.put("img",R.drawable.dog1);
list.add(map);
}
cursor.close();
db.close();
}
catch(Exception exp){}
return list;
} 展开
1个回答
展开全部
因为你的map 只有一个,改成这样:
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
String sql="select*from items_list";
try{
db=dabaseHelper.getWritableDatabase();
Cursor cursor=db.rawQuery(sql, null);
while(cursor.moveToNext()){
Map<String,Object> map=new HashMap<String,Object>();
String title=cursor.getString(1);
String details=cursor.getString(2);
String time=cursor.getString(3);
map.put("title",title);
map.put("info",time);
map.put("img",R.drawable.dog1);
list.add(map);
}
cursor.close();
db.close();
}
catch(Exception exp){}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询