android sqlite listview游标问题

时间:2010-11-23 04:18:50

标签: android database sqlite

来自我的main.java:

    Cursor c = db.getDue();

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

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

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
            R.layout.lventer, c, columns, to);
    ListView lv1 = (ListView)findViewById(R.id.ListView01);

    lv1.setAdapter(mAdapter);

从我的数据库包装类:

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

如果我使用第二个选择语句然后崩溃,除非我从游标适配器/列表视图绑定中删除“日期”,如果我这样做那么它将在列表视图中显示返回的_id,但我想看到两个_id和列表视图中的日期。

我被告知第二个语句可能会因为max函数返回一个不同的日期类型(我不是很有sql文字),但我认为sqlite在数据类型方面是松散的吗?任何人都可以提前帮助。

** UPDATE **这是在列表视图中不能使用2列的命令:

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

1 个答案:

答案 0 :(得分:2)

使用此:

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