我只想显示日期等于 getdate(string data) 函数中我的字符串的那些行,所以我尝试更改工作函数,该函数使用 SELECT from ... 命令在 Listview 中显示数据库中的所有条目,但它没有不工作。如何从我的日历中获取这些事件?
正确工作功能:
public Cursor getAllContacts()
{
return database.query("calendar_events", new String[] {"_id", "event"},
null, null, null, null, "date");
}
我想将其更改为:
public Cursor getdate(String data){
return database.rawQuery("SELECT event FROM calendar_events WHERE date = '" + data + "'", new String[] { "event"});
}
我更改的函数片段:getAllContacts(代码正常工作并在列表视图中显示日历中的事件,单击它后我可以输入此数据库条目中的所有数据)到getdate(“2012-12-30”) :
private class GetContacts extends AsyncTask<Object, Object, Cursor>
{
DatabaseConnector dbConnector = new DatabaseConnector(DayPlan.this);
@Override
protected Cursor doInBackground(Object... params)
{
dbConnector.open();
return dbConnector.getdate("2012-12-30");
}
@Override
protected void onPostExecute(Cursor result)
{
conAdapter.changeCursor(result); // set the adapter's Cursor
dbConnector.close();
}
}
我遇到的错误:
01-02 14:32:13.828: E/AndroidRuntime(809): FATAL EXCEPTION: AsyncTask #1
01-02 14:32:13.828: E/AndroidRuntime(809): java.lang.RuntimeException: An error occured while executing doInBackground()
01-02 14:32:13.828: E/AndroidRuntime(809): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.lang.Thread.run(Thread.java:856)
01-02 14:32:13.828: E/AndroidRuntime(809): Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 0 parameters.
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteProgram.bind(SQLiteProgram.java:212)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:166)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
01-02 14:32:13.828: E/AndroidRuntime(809): at com.examples.android.calendar.DatabaseConnector.getdate(DatabaseConnector.java:87)
01-02 14:32:13.828: E/AndroidRuntime(809): at com.examples.android.calendar.DayPlan$GetContacts.doInBackground(DayPlan.java:70)
01-02 14:32:13.828: E/AndroidRuntime(809): at com.examples.android.calendar.DayPlan$GetContacts.doInBackground(DayPlan.java:1)
01-02 14:32:13.828: E/AndroidRuntime(809): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-02 14:32:13.828: E/AndroidRuntime(809): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-02 14:32:13.828: E/AndroidRuntime(809): ... 4 more
如何仅显示日期为 2012-12-30 的事件?