开发者

android sqlite listview cursor problem

From my main.java:

    Cursor c = db.getDue();

    String[] columns = new String[] { "_id", "date" };  

    int[] to = new int[] { R.id.num, R.id.date };

    S开发者_开发百科impleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
            R.layout.lventer, c, columns, to);
    ListView lv1 = (ListView)findViewById(R.id.ListView01);

    lv1.setAdapter(mAdapter);

From my database wrapper class:

    public Cursor getDue() {
    //String getdue = "SELECT * FROM tb1"; // this returns _id+date and displays them in the listview via the cursor adapter, defined above
    String getdue = "SELECT _id, max(date) AS date FROM tb1 GROUP BY _id";// this only works if I remove the "date" bindings defined above, only letting me see the _id, i want to see both _id and date in the lit view.

    return db.rawQuery(getdue,null);

If I use the second select statment then it crashes unless I remove the "date" from the cursor adapter/listview bindings, if I do this then It will show the returned _id in the listview, but I want to see both _id and date in the listview.

I have been told that the second statment might returns a different type for date because of the max function ( I am not very sql literate, yet), but I thought that sqlite was loose with datatypes? Can anybody help, thanks in advance.

** UPDATE** This is the command that wont work with 2 columns fr the list view:

 SELECT _id, max(date) FROM jobs GROUP BY _id HAVING max(date) < (date-21)


Use this:

String getdue = "SELECT _id, max(date) AS date FROM tb1 GROUP BY _id";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜