数据库插入后刷新的ListView [英] Refresh an listView after insert on database

查看:253
本文介绍了数据库插入后刷新的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要刷新列表视图插入后,或在数据库中删除。我寻找,我发现notifyDataSetChanged(),但我不知道如何使用它。

I want to refresh the listView after an insert or delete in the database.. I search and i found notifyDataSetChanged () but i don't know how to use it..

有人能解释如何做到这一点?即使是用不同的方式。

Someone can explain how to do this? Even by a different way..

推荐答案

在单击删除按钮执行以下操作:

When the delete button is clicked do the following:


  1. 从数据库中删除相应的列表项。

  2. 通过执行再次写满列表中查询获取你的列表中的新指针。

  3. 绑定使用新的光标到目录<一个href=\"http://developer.android.com/reference/android/widget/CursorAdapter.html#changeCursor%28android.database.Cursor%29\">changeCurosr().

  4. 呼叫<一个href=\"http://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged%28%29\">notifyDataSetChanged()在适配器上。

  1. Delete the corresponding list item from the database.
  2. Get an new cursor for your list by executing the query which fills the list again.
  3. Bind the new cursor to the list using changeCurosr().
  4. Call notifyDataSetChanged() on the adapter.

这篇关于数据库插入后刷新的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆