使用日历查询

时间:2010-11-30 12:44:56

标签: android calendar

我正在尝试构建一个从本机日历中获取事件的查询,我已经用这3个单词中的1个单词存储了描述:“google”,“yahoo”,“stackoverflow”

例如:description =“google”,

截至目前,我已经进行了如下查询:

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=" + calId,
        null, "startDay ASC, startMinute ASC"); 

现在,我想用描述部分进行查询,我该如何?我当前的实施是错误的,请告诉我一个正确的方式,就好像你知道!!!

更新

到目前为止我已经完成了:

public String Fetch_Events_Detail(long From_milliseconds, String kind_website)
 {
  String event_detail = null;

  Uri.Builder builder = calendar_events_URI.buildUpon();
        //long now1 = new Date().getTime();
        ContentUris.appendId(builder, From_milliseconds);
        ContentUris.appendId(builder, From_milliseconds + DateUtils.DAY_IN_MILLIS);


       /* Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
                new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(kind_website)}, "startDay ASC, startMinute ASC"); 
        */

        Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" },"Calendars._id=" + calId,
                null, "startDay ASC, startMinute ASC"); 

        if(eventCursor != null)
        {

         while (eventCursor.moveToNext()) 
         {
            String uid2 = eventCursor.getString(0);
            String event_title = eventCursor.getString(1);
            String event_start = eventCursor.getString(2);
            String event_description = eventCursor.getString(5);

            try
            {
                // SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
             SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                Date resultdate = new Date(Long.parseLong(event_start));

                event_detail=sdf.format(resultdate)+"  "+event_title;
                event_detail.trim();

                if(event_description.trim().equalsIgnoreCase(kind_website))
                { 
                 return event_detail;
                }
            }
            catch(NumberFormatException e)
            {
             Log.i("Exception raised", "");
            }
          }
        }

        return null;
 }

感谢名单

1 个答案:

答案 0 :(得分:2)

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
        new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC"); 

尝试不使用calId

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "description = ?",
        new String[] {DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC");