2013-04-24 2 views
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; 

    } 

} 

ответ

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); 
+0

Спасибо за ответ. Добавленная дата (5 дней в вашем примере) должна основываться на выбранной кнопке. Он изменяется для каждой кнопки. Вы можете помочь? Я предполагаю, что число 5 вместо этого будет строковым значением, которое было установлено на каждой кнопке? – JeffK

+0

Вы можете добавить любое количество дней в календарь. Если вы хотите установить напоминание через 10 дней, передайте значение как 10. попытайтесь найти некоторую логику, чтобы выяснить, какая кнопка нажала кнопку. – deepdroid

+0

do 'parseInt (String)', если вы хотите сделать 5 переменной из строки. – StoneBird

Смежные вопросы