android notifyDataSetChanged不管用


代码很简单 如下:
java代码:

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


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

sca.notifyDataSetChanged();


但是 不行 ui没有变化

后来 上网找 说是数据源必须改变了  
java代码:

    cursor = cs.getAll();

 sca.notifyDataSetChanged();

 


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

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

    cursor = cs.getAll();

                       sca.changeCursor(cursor);

                       sca.notifyDataSetChanged();

 


这样 就ok 了

你可能感兴趣的:(android)