gpt4 book ai didi

android - SimpleCursorAdapter 替代品

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:24:41 25 4
gpt4 key购买 nike

我正在使用已弃用的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com