ListView当数据库更新的时候,随之也更新问题

来源:互联网 发布:淘宝卡怎么办理 编辑:程序博客网 时间:2024/04/29 08:29

1、listView的跟新问题

或许这个网址有用:http://www.iteye.com/problems/77500

问题是:我操作的是andorid里自己系统维护的数据库,当我删除了数据,或更新了数据,想更新我界面的listview,用sAdapter.notifyDataSetChanged();没有效果?应该怎样实现呢?

其他网络的建议:

                   1、给ListView重新设置一下值,然后notifyDataSetChanged();

                    2、listview 的 invalidate  重新加载一次listview的值。cusor的,我好想还木用过invalidate。

                   3、我是在需要的时候cursor.requery();不知道有没有更好的方法..

依靠第三种,可以更新。

public void freshData(){
Cursor cursor = adapter.getCursor();
cursor.requery();
adapter.swapCursor(null);
adapter.swapCursor(cursor);
adapter.notifyDataSetChanged();
}

在onresume()方法中添加这方法。就可以在从其他的activity中回到这activity中数据会刷新。

但是在原本的activity中刷新中还是在学习中


0 0
原创粉丝点击