0
我被困了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;
}
}
感謝您的答覆。添加日期(在您的示例中爲5天)需要基於他們選擇哪個按鈕。它隨每個按鈕而改變。你能幫我嗎?我猜數字5會改爲每個按鈕上設置的字符串值? – JeffK 2013-04-24 20:22:09
您可以將任意數量的日期添加到日曆中。如果您想在10天后設置提醒,請將值傳遞爲10.嘗試使用某種邏輯來確定用戶點擊了哪個按鈕。 – deepdroid 2013-04-24 20:27:07
do'parseInt(String)'如果你想從字符串中創建5個變量。 – StoneBird 2013-04-24 20:33:44