Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i get SQLite to sort by date properly using YYYY-MM-DD format?
    primarykey
    data
    text
    <p>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. </p> <p>My activity extends listview and uses SimpleCursorAdapter to populate the listview. My date column is a TEXT field formatted like this "YYYY-MM-DD"</p> <p>Here is my database query function, I base my database helper class off of the google notepad example.</p> <pre><code>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; } </code></pre> <p>And I hook it to the ListView like this:</p> <pre><code>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()); } </code></pre> <p>The problem I am having is that my cursor doesn't seem sorted properly, my weeklist looks like this:</p> <pre><code>2010-7-19 2010-7-23 2010-7-24 2010-7-6 </code></pre> <p>Instead of being properly sorted. I'm probably missing something really obvious, since I'm a total noob trying to teach myself.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload