如何使用YYYY-MM-DD格式让SQLite按日期排序?

Ben*_*Gmo 2 java sqlite android

我正在制作一个应用程序,需要按日期对Sqlite表进行排序,并在列表视图中显示该周的日期和总工时.

我的活动扩展了listview,并使用SimpleCursorAdapter填充列表视图.我的日期列是一个TEXT字段,格式为"YYYY-MM-DD"

这是我的数据库查询功能,我的数据库助手类基于google记事本示例.

public Cursor getAllWeeks()
    {
        Cursor mCursor = mDb.query(true, DATABASE_TABLE, null, null, null, null, null, "weekdate ASC", null);


        if (mCursor != null)
        {
            mCursor.moveToFirst();
        }

        return mCursor;
    }
Run Code Online (Sandbox Code Playgroud)

我把它挂钩到ListView,如下所示:

public class WeekList extends ListActivity implements OnClickListener{
    final static int DELETE_ID = Menu.FIRST + 1;

    public static NotesDbAdapter DBadapter;
    public static Cursor ListCursor;

    static final String[] displaycolumns = {"weekdate", "weektotalhours"};
    static final int[] listitemviews = {R.id.TextViewListItem1, R.id.TextViewListItem2};

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.weeklist);
        Log.i("bendebug", "logtest");

        DBadapter = new NotesDbAdapter(this);
        DBadapter.open();
        ListCursor = DBadapter.getAllWeeks();


        this.setListAdapter(new SimpleCursorAdapter(this, R.layout.listitemlayouts, ListCursor, 
                displaycolumns, listitemviews));
        findViewById(R.id.ButtonAddWeek).setOnClickListener(this);

        //Activate the context menu
        registerForContextMenu(getListView());

    }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我的光标似乎没有正确排序,我的周列表如下所示:

2010-7-19
2010-7-23
2010-7-24
2010-7-6
Run Code Online (Sandbox Code Playgroud)

而不是正确排序.我可能错过了一些非常明显的东西,因为我是一个试图自学的总菜鸟.

显然我缩短了代码以使其更具可读性,因为活动的其余部分与AFAIK无关,但我很乐意根据请求发布活动的完整代码,无论如何它都是基本的.

dan*_*n04 6

使用前导零来表示月份和日期.