嘿,我使用列表视图来演示存储在数据库中的条目。我还有一个EditText元素和一个将EditText的内容添加到数据库中的按钮。要将视图绑定到我使用SimpleCursorAdapter和下面填入功能的数据库内容:使用SimpleCursorAdapter更新Android ListView
private void populate() {
cursor = dbAdapter.getAllItems();
startManagingCursor(cursor);
String[] from = new String[] { DBAdapter.KEY_TASK };
int[] to = new int[] { android.R.id.text1 };
// Now create an array adapter and set it to display using our row
cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to);
list.setAdapter(cursorAdapter);
}
如果我增加了一个新的项目,通过点击按钮,我想刷新列表视图但这只是与填入功能的工作原理而不是使用通用适配器功能notifyDataSetChanged();
。我有错误还是这是刷新列表视图的正确方法?
只需提一下:'repery()'已被弃用。 [Documentation](http://developer.android.com/reference/android/database/Cursor.html#requery())对此有清晰的记录。 – 87element
我知道了,我没有把这句话说得很对,重新措辞它:> – Jack
嘿杰克感谢您的回复,我发现我忘了说上面的代码是我的'populate()'函数,我称它为我的'onCreate()'方法,如果我点击“添加”按钮。我只想知道这是否是调用此方法而不是调用基本适配器类的通用'notifyDataSetChanged()'方法的好方法。 –