`

2011.07.05——— android notifyDataSetChanged不管用

阅读更多
2011.07.05——— android notifyDataSetChanged不管用

参考:http://blog.csdn.net/xiakq/article/details/6576763
http://www.xiaoyao.net/?p=81

代码很简单 如下:

SimpleCursorAdapter sca = new SimpleCursorAdapter(ClassBaseActivity.this, R.layout.content_item, cursor, new String[]{"name"}, new int[]{R.id.content_text});


我建立了一个SimpleCursorAdapter 我的crusor发生的变化 增加或者删除了一条数据 这时 我就需要更新SimpleCursorAdapter ,然后 我就这样写了:

sca.notifyDataSetChanged();


但是 不行 ui没有变化

后来 上网找 说是数据源必须改变了 

                   
cursor = cs.getAll();
                    sca.notifyDataSetChanged();


然后 我就重新获得了crusor 但是依然不行

最后 终于在网上找到 必须告诉SimpleCursorAdapter 我们改变了数据源 也就是:

                  
 cursor = cs.getAll();
                    sca.changeCursor(cursor);
                    sca.notifyDataSetChanged();



这样 就ok 了
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics