Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2644265
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: 嵌入式

2012-02-16 17:06:46

参考:

这个问题一直很纠结,用sqlite的update, del, add都正常,但遇到search就不好使。
曾经写过类似下面的代码:
private void UpdataAdapter() { // 获取数据库的Curso对象
if (mCursor != null && mCursor.getCount() >= 0) {
adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
//android.R.layout.simple_list_item_2,
R.layout.list_700,
// Give the cursor to the list adapter
mCursor,
// Map the DISPLAY_NAME column to...
new String[] { Phone.NUMBER ,Phone.DISPLAY_NAME },
// The "text1" view defined in the XML template
//new int[] { android.R.id.text1, android.R.id.text2 });
new int[] { R.id.viewName, R.id.viewNum });

setListAdapter(adapter);
}
}
search后再调用它来刷新view,也正常,但用C++的观念来看不点不符合逻辑。

后来无意中在找到了答案:
 adapter.changeCursor(newCursor);//网上看到很多问如何更新ListView的信息,采用CusorApater其实很简单,换cursor就可以

  public void changeCursor(Cursor cursor) {
        Cursor old = swapCursor(cursor);
        if (old != null) {
            old.close();
        }
    }
再执行一次cursor.close()就没有必要了。







阅读(4052) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~