【问题标题】:How to sort data using Cursor with Content Provider and Cursor Adapter?如何使用带有 Content Provider 和 Cursor Adapter 的 Cursor 对数据进行排序?
【发布时间】:2016-01-18 11:10:09
【问题描述】:

我有一个Content Provider 和一个Cursor Adapter。我表中的一列是int。我想按此列排序我的表,因此Adapter 将相应地显示数据。我试图这样做: 在Activity

Cursor c = getContentResolver().query(
                PetContract.Dogs.CONTENT_URI,
                null, null, null,
                PetContract.Dogs.DATE + " ASC");

        testAdapter = new TestAdapter(this, c);
        c.close();
        list.setAdapter(testAdapter);
        getLoaderManager().initLoader(1, null, this);
        registerForContextMenu(list);

Adapter 构造函数中:

public TestAdapter(Context context, Cursor c) {
        super(context, c);
    }

但它没有工作......

【问题讨论】:

    标签: cursor android-contentprovider android-cursoradapter


    【解决方案1】:

    想通了。在我的Activity:

     @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new CursorLoader(this,
                    PetContract.Dogs.CONTENT_URI,
                    null,
                    null,
                    null,
                    PetContract.Dogs.DATE + " collate localized asc"
            );
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 2012-04-30
      相关资源
      最近更新 更多