Android SimpleAdapter显示问题

        当用户第一次点击软件时,第一个版本只是显示记录的标题,没有显示记录的日期,所以应该加上去?
   解决方案:
   原来在MainShow.java代码如下:
   while (c.moveToNext()) {
Map<String, Object> map = new HashMap<String, Object>();
String strTime=c.getString(c.getColumnIndex("noteTime"));
map.put("noteTime", strTime);
String strName = c.getString(c.getColumnIndex("noteName"));
// 如果标题内容超过16个字节,则截取前6个字节+“...”
if (strName.length() > 26) {
map.put("noteName", strName.substring(0, 26));
} else {
map.put("noteName", strName);
}
map.put("noteId", c.getInt(c.getColumnIndex("noteId")));
list.add(map);
}
c.close();
sdb.close();
if (count > 0) {
//  这里加载R.layout.items列表项布局文件
sa = new SimpleAdapter(MainShow.this, list, R.layout.items,
new String[] { "noteName", "noteTime" }, new int[] {
R.id.noteName, R.id.noteTime });
lv.setAdapter(sa);
}
     但经过导入到手机上,证明只能显示记录的标题,无法显示时间。
   解决方案是:
       把记录的时间加到记录标题的后面,连接成一个字段,修改代码如下:
   while (c.moveToNext()) {
Map<String, Object> map = new HashMap<String, Object>();
String strTime=c.getString(c.getColumnIndex("noteTime"));
map.put("noteTime", strTime);
String strName = c.getString(c.getColumnIndex("noteName"));
// 如果标题内容超过16个字节,则截取前6个字节+“...”
if (strName.length() > 26) {
map.put("noteName", strName.substring(0, 26)+strTime);
} else {
map.put("noteName", strName+strTime);
}
map.put("noteId", c.getInt(c.getColumnIndex("noteId")));
list.add(map);
}
c.close();
sdb.close();
if (count > 0) {
//  这里加载R.layout.items列表项布局文件
sa = new SimpleAdapter(MainShow.this, list, R.layout.items,
new String[] { "noteName", "noteTime" }, new int[] {
R.id.noteName, R.id.noteTime });
lv.setAdapter(sa);
}
    再次运行,可以显示标题和时间。

你可能感兴趣的:(android,SimpleAdapter)