使用字符串值设置日历订单日期

时间:2013-04-24 19:59:50

标签: android calendar

我被困了2天后终于放弃了。我需要你对日历功能的帮助。此人选择一个产品(在按钮上)并设置一条消息,并允许他们在重新排序时添加提醒。现在我打开日历,但无法根据该产品设置日历日期。我不确定如何设置字符串值,调用它,并设置日历日期。我知道这是基本的东西,但我很感激帮助!对不起冗长的代码。我想确保包含所有相关内容。

这是我的代码:

Button reorder1 = (Button) findViewById(R.id.rotramadol);
Button reorder2 = (Button) findViewById(R.id.roaciphex);
Button reorder3 = (Button) findViewById(R.id.roflexeril);
reorder1.setOnClickListener(this);
reorder2.setOnClickListener(this);
reorder3.setOnClickListener(this);

@Override
public void onClick(View v) {
    if (v.getId() == R.id.rotramadol) {
//this one needs the calendar set 10 days from now
        AlertDialog ad = new AlertDialog.Builder(this)
                .setMessage(
                        "Order Quantity 90 tabs requires 10 days")
                .setTitle("Tramadol")
                .setPositiveButton("Set Reminder", this)
                .setNegativeButton("OK", this).setCancelable(false)
                .create();
        ad.show();
    } else if (v.getId() == R.id.roaciphex) {
//this one needs the calendar set 25 days from now
        AlertDialog ad1 = new AlertDialog.Builder(this)
                .setMessage("Order Quantity 30 tabs requires 25 days")
                .setTitle("Aciphex")
                .setPositiveButton("Set Reminder", this)
                .setNegativeButton("OK", this).setCancelable(false)
                .create();
        ad1.show();
    } else if (v.getId() == R.id.roflexeril) {
//this one needs the calendar set 7 days from now
        AlertDialog ad2 = new AlertDialog.Builder(this)
                .setMessage("Order Quantity 30 tabs requires 7 days")
                .setTitle("Flexeril")
                .setPositiveButton("Set Reminder", this)
                .setNegativeButton("OK", this).setCancelable(false)
                .create();
        ad2.show();


@Override
public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

    switch (which) {
    case DialogInterface.BUTTON_POSITIVE: // yes

        Intent intent = new Intent(Intent.ACTION_INSERT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra(Events.TITLE, "Reorder");
        intent.putExtra(Events.EVENT_LOCATION, "");
        intent.putExtra(Events.DESCRIPTION,
                "https://www.place they reorder.com");

        GregorianCalendar calDate = new GregorianCalendar();
        intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                calDate.getTimeInMillis());
        intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                calDate.getTimeInMillis());

        intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

        intent.putExtra(Events.RRULE, "FREQ=DAILY;COUNT=1;");

        intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
        intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

        startActivity(intent);

        break;

    case DialogInterface.BUTTON_NEGATIVE: // no

        dialog.cancel();

        break;
    default:
        break;

    }

}

1 个答案:

答案 0 :(得分:0)

我假设您尝试根据用户选择设置日历事件,请尝试以下代码

                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, 5/*how many days from today*/); 
                    Intent intent = new Intent(Intent.ACTION_EDIT);
                    intent.setType("vnd.android.cursor.item/event");
                    intent.putExtra(Events.TITLE, "your title");
                    intent.putExtra("beginTime", calendar.getTime());
                    intent.putExtra("endTime", calendar.getTime() + DateUtils.MINUTE_IN_MILLIS * 30);
                    intent.putExtra(Events.EVENT_TIMEZONE, calendar.getTimeZone());
                    startActivity(intent);