android - SimpleCursorAdapter 替代品

标签 android android-listview android-cursoradapter

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

相关文章:

java - 带 ListView 的音频播放器

android - 从 ListFragment 中的自定义 CursorAdapter 启动操作模式

android - 在 ExpandableListView 上分组数据

android - ActivityOptions.makeSceneTransitionAnimation 创建一个空 Activity

android - 如何从 URL 加载图像? (关于 SO 的所有答案都不起作用/已弃用)

android - 如何在 ListView 中使用 DataBinding?

android - 如果 listView 从下到上滚动,如何监听?

android - CursorAdapter 缓慢/不稳定的滚动

android - 在没有 lambda 表达式的情况下检查 Android 上的互联网访问(Levit)

android - 从Listview的onClick方法启动 Activity ( fragment )