我正在使用已弃用的 SimpleCursorAdapter 将数据从 Cursor 显示到 ListView。我添加了额外的参数 0
,它删除了弃用的警告,但我想使用更好的方式来显示数据。我读过一些关于 Loader
的内容,但不知道如何实现它。下面的代码有什么更好的替代方法?如何将此代码转换为使用 Loader?
Cursor c = mDbHelper.getAllRecords();
startManagingCursor(c); //this is also deprecated
String[] from = new String[] { "Name" };
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter names =
new SimpleCursorAdapter(this, R.layout.names_row, c, from, to, 0);
setListAdapter(names);
最佳答案
适配器 = 新的 SimpleCursorAdapter(这个,
android.R.layout.simple_list_item_2, cursor, from, to, 1);
这将执行自动重新查询。 1 设置为真,0 设置为假。
关于android - SimpleCursorAdapter 替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14816714/