日历事件查询的选择 [英] Selection of Calendar event query

查看:251
本文介绍了日历事件查询的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着读出从一个特定的日历事件。以下是code我尝试使用。但我不知道该如何选择了样子。我想使用日历ID为的选择。如果没有选择(空)读取所有的日历,但我只想之一。
查询看起来是这样的:

I try to read out events from a specific calendar. Following is the code I try to use. But I dont know how the selection has to look like. I want to use the calendar id for the selection. Without the selection (null) it reads out all calendars, but I just want one. A query looks like this:

public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) 

选择:结果
过滤器宣称要返回的行,格式化为一个SQL WHERE子句(不包括WHERE本身)。传递null将返回给定的URI的所有行。

selection:
A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.

这code是第一次尝试一个选择:

This code is the first try with a selection:

            Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
            ContentUris.appendId(builder, now - DateUtils.DAY_IN_MILLIS);
            ContentUris.appendId(builder, now + DateUtils.DAY_IN_MILLIS);

            Cursor mCursor = null;
            final String[] projection = new String[]
            { CalendarContract.Events.TITLE, CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND};

            mCursor = getContentResolver().query(
                builder.build(), projection, Instances._ID  + calendarID, null, null);
                mCursor.moveToFirst();  

这就是从上面code中的错误:

Thats the error from above code:

09-29 00:07:41.800: E/AndroidRuntime(14507): FATAL EXCEPTION: TweetCollectorTimer
09-29 00:07:41.800: E/AndroidRuntime(14507): android.database.sqlite.SQLiteException: no such column: _id3: , while compiling: SELECT title, dtstart, dtend FROM Instances INNER JOIN view_events AS Events ON (Instances.event_id=Events._id) WHERE (begin<=? AND end>=?) AND (_id3)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at android.content.ContentResolver.query(ContentResolver.java:311)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at de.ring.AppService$1.run(AppService.java:96)
09-29 00:07:41.800: E/AndroidRuntime(14507):    at java.util.Timer$TimerImpl.run(Timer.java:284)

编辑:

非常感谢,我把它改为:

Thanks a lot, I changes it to:

            mCursor =   getContentResolver().query(
                    builder.build(), projection, Instances.CALENDAR_ID  + " = ?",
                    new String[]{""+calendarID}, null);

其重要使用CALENDAR_ID而不仅仅是_ID。

Its important to use CALENDAR_ID and not just _ID.

推荐答案

让这个

  getContentResolver().query(
                    builder.build(), projection, Instances._ID  + "=?",
new String[]{""+calendarID}, null);

而不是这种

getContentResolver().query(
                builder.build(), projection,
 Instances._ID  + calendarID, null, null);

由于第三个参数需要选择字符串,你通过这个 Instances._ID + calendarID 这将是评估这种

SELECT ........ WHERE _id3; 

它的日历ID数追加到列名。

it append the number of the calendar id to the column name .

这篇关于日历事件查询的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆