【问题标题】:Sorting a Cursor in Android to be used in SimpleCursorAdapter在 Android 中对要在 SimpleCursorAdapter 中使用的光标进行排序
【发布时间】:2011-03-02 09:47:54
【问题描述】:

我正在为我的 Android 课程做一个项目。该应用程序非常丑陋,也不是很有用,但它是为了证明我们可以实现 Content Providers。我遇到的问题是对光标进行排序。这是我的代码:

setContentView(R.layout.main);
String[] projection = new String[] {Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER};
    Cursor mCursor = this.getContentResolver().query(Phone.CONTENT_URI, projection , null, null, "Phone.CONTACT_ID ASC");
    startManagingCursor(mCursor);

    ListAdapter adapter = new SimpleCursorAdapter(
            this, // Context.
            R.layout.rows,
            mCursor,                                              
            new String[] {Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER}, 
            new int[] {R.id.text1, R.id.text2, R.id.text3});
    setListAdapter(adapter);

【问题讨论】:

  • 您需要先对列表进行排序,还是需要在列表视图显示后才能对其进行排序?

标签: android sorting cursor


【解决方案1】:

不要这样做:

..., "Phone.CONTACT_ID ASC");

试试这个

..., Phone.CONTACT_ID + " ASC");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多