我正在尝试使用LoaderCallbacks创建Listview我能够看到列表中的所有元素。但是现在我想对它进行排序,以便DB中的最新项目是第一个在顶部。我在数据库中有一个名为COLUMN_MESSAGE_DATE的Coulmn,其中包含一个时间戳,我希望最新的行位于顶部。在onCreateLoader中,当我返回加载程序时,我按此Coulmn排序,但最新行仍然在底部...我错过了什么吗?
public class MessageListFragment extends Fragment implements LoaderCallbacks<Cursor>{
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
// Create the Cursor that will take care of the data being displayed
Log.d("TAG", "onCreateLoader...");
return new CursorLoader(getActivity(),CONTENT_URI, null, null, null,DataBase.COLUMN_MESSAGE_DATE);//I thought this should sort the list by date...
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor)
{
// Now Bind the data to the View
Log.d("TAG", "onLoadFinished...ARG1= " + cursor);
mCusrorAdapter = new CustomCursorAdapter(getActivity(), cursor);
mListView.setAdapter(mCusrorAdapter);
}
}
答案 0 :(得分:2)
虽然我不确定没有看到您的数据,但时间戳通常是递增值。也就是说,当前时间戳的值大于旧的时间戳。默认排序顺序为ASCending。在这里,我相信你想要DESCending:
return new CursorLoader(getActivity(),CONTENT_URI, null, null, null,DataBase.COLUMN_MESSAGE_DATE + " DESC");