开发者

Setting custom date to android calendar

I am creating开发者_Go百科 an app and I am trying to get the calendar functionality working properly. So far the event gets added but I cannot get the custom date correct. I believe it may be the format but I am struggling to get that correct.

The code I got is the following:

@Override
    public void onItemClick(AdapterView<?> adp, View v, int position, long id) 
    {
        FixtureSupport fixture = (FixtureSupport) adapter.getItem(position);

        try
        {
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date date = (Date)formatter.parse("10/05/2012");

            Intent event = new Intent(Intent.ACTION_EDIT);
            event.setType("vnd.android.cursor.item/event");
            event.putExtra("title", "Rugby Match");
            event.putExtra("description", fixture.getHome() + " V " + fixture.getAway());
            event.putExtra("eventLocation", fixture.getVenue());
            event.putExtra("hasAlarm", 1);
            event.putExtra("startTime", date);
            startActivity(event);
        }
        catch (Exception e)
        {
            System.err.println("Error");
        }
    }

When I click the item on the screen, the title / description / location all work. But when I try and set the startTime (date of the event) it will not work. Currently when I create a event thats meant to be starting tomorrow, it says the event will begin in 1minute!

Help will be appreciated, thanks guys!


Did you try:

event.putExtra("startTime", "10/05/2012");

And when you are accessing passed variables:

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = formatter.parse(bundle.getString("startTime"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜