如果使用 CursorAdapter,如何更新 ListView? [英] How to update ListView in case of CursorAdapter usage?
本文介绍了如果使用 CursorAdapter,如何更新 ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我之所以这么问是因为 requery()
已被弃用.现在刷新 ListView
的最佳方法是什么?
The reason I'm asking that is because requery()
is deprecated. What is the best way now to refresh your ListView
?
推荐答案
requery()
更新 Cursor
,而不是 CursorAdapter
.正如你所说,它已被弃用,它的替代品是:
requery()
updates a Cursor
, not a CursorAdapter
. As you say, it has been deprecated, and its replacement is:
oldCursor = myCursorAdapter.swapCursor(newCursor); // hands you back oldCursor
或:
myCursorAdapter.changeCursor(newCursor); // automatically closes old Cursor
myCursorAdapter.notifyDataSetChanged()
通知 ListView
数据集已经改变,它应该自己刷新
myCursorAdapter.notifyDataSetChanged()
notifies the ListView
that the data set has changed, and it should refresh itself
这篇关于如果使用 CursorAdapter,如何更新 ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文