我怎样才能SQLite的正常使用YYYY-MM-DD格式按日期排序? [英] How can i get SQLite to sort by date properly using YYYY-MM-DD format?

查看:1107
本文介绍了我怎样才能SQLite的正常使用YYYY-MM-DD格式按日期排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做,需要按日期和显示只是日期和总小时数排序周的SQLite表一个应用程序,每周工作在ListView。

I'm making an app that needs to sort a Sqlite table of weeks by date and display just the date and the total hours worked that week in a listview.

我的活动扩展列表视图,并使用SimpleCursorAdapter填充列表视图。我的日期列的格式是这样的YYYY-MM-DD

My activity extends listview and uses SimpleCursorAdapter to populate the listview. My date column is a TEXT field formatted like this "YYYY-MM-DD"

下面是我的数据库查询功能,我基地我的数据库辅助类关闭谷歌记事本的例子。

Here is my database query function, I base my database helper class off of the google notepad example.

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;
    }

和我把它挂到像这样的ListView:

And I hook it to the ListView like this:

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());

    }

我遇到的问题是,我的光标似乎没有适当的排序,我weeklist看起来是这样的:

The problem I am having is that my cursor doesn't seem sorted properly, my weeklist looks like this:

2010-7-19
2010-7-23
2010-7-24
2010-7-6

而不是被正确排序。我可能失去了一些东西真的很明显,因为我是一个总的小白试图教自己。

Instead of being properly sorted. I'm probably missing something really obvious, since I'm a total noob trying to teach myself.

很明显,我缩短了code,以使其更具可读性,因为活动的其余部分是无关紧要据我所知,但我会很乐意发布完整的code应要求该活动,这是很基本的反正。

Obviously i shortened the code to make it more readable, since the rest of the activity is irrelevant AFAIK but I would be happy to post the complete code for the activity on request, it's really basic anyway.

推荐答案

月和日使用前导零。

这篇关于我怎样才能SQLite的正常使用YYYY-MM-DD格式按日期排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆