选择与sqlite中的月份值匹配的记录

时间:2014-09-23 07:46:21

标签: android sqlite

我选择了与给定月份名称匹配的记录,并使用简单的游标适配器,我必须在列表视图中显示它。我没有收到任何错误,但列表没有显示任何内容。

这是我的代码

public Cursor readData(String month){
    String SELECT_MON = "select * from " + Diary_DBHandler.TABLE_PERSONAL + " where strftime('%m'," +Diary_DBHandler.PERSONAL_DATE + ") = '" + month +"';";
    Cursor c = database.rawQuery(SELECT_MON, null);
    if (c != null) {
        c.moveToFirst();
    }
    return c;
}

Cursor c = dbcon.readData(month);

    String[] from = new String[]{Diary_DBHandler.PERSONAL_ID,Diary_DBHandler.PERSONAL_TITLE,Diary_DBHandler.PERSONAL_DESC,Diary_DBHandler.PERSONAL_AMT_SPENT,
            Diary_DBHandler.PERSONAL_PAYMETHOD, Diary_DBHandler.PERSONAL_DATE };
    int[] to = new int[]{R.id.persID_tv,R.id.persTitle_tv,R.id.persDesc_tv,R.id.persAmt_tv,
            R.id.persPaymethod_tv, R.id.persDate_tv};

    adapter = new SimpleCursorAdapter(Diary_ListOfPersonalExpenses.this,R.layout.diary_personal_exp_entries,c,from,to);
    adapter.notifyDataSetChanged();

1 个答案:

答案 0 :(得分:0)

strftime documentation说:

  

%m月:01-12

您必须将month的值转换为相同的格式才能进行比较。