0

ユーザーがリマインダーを設定する日時を選択できるようにする Date_Picker をセットアップしましたが、注文する薬を選択する場所をセットアップする必要があり、再注文のリマインダーを将来の x 日数に設定します. 薬「A」を注文すると、5 日後にリマインダーが届きます。彼らが薬「B」を注文した場合、10 日後にリマインダーが送信されます。薬「C」15日。Date_Picker への参照を削除する必要があると思いますか? そして私のコード mCalendar.set(Calendar.Year, year) で年を何らかの形で文字列として使用していますか? 私は今かなり迷っています!これが私が持っているコードです。ありがとうございました。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDbHelper = new RemindersDbAdapter(this);

    setContentView(R.layout.reminder_edit);

    mCalendar = Calendar.getInstance(); 
    mTitleText = (EditText) findViewById(R.id.title);
    mBodyText = (EditText) findViewById(R.id.body);
    mDateButton = (Button) findViewById(R.id.reminder_date);
    mTimeButton = (Button) findViewById(R.id.reminder_time);

    mConfirmButton = (Button) findViewById(R.id.confirm);

    mRowId = savedInstanceState != null ?savedInstanceState.getLongRemindersDbAdapter.KEY_ROWID) 
                                        : null;

    registerButtonListenersAndSetDefaultText();
}

private void setRowIdFromIntent() {
    if (mRowId == null) {
        Bundle extras = getIntent().getExtras();            
        mRowId = extras != null ? extras.getLong(RemindersDbAdapter.KEY_ROWID) 
                                : null;

    }
}


@Override
protected Dialog onCreateDialog(int id) {
    switch(id) {
        case DATE_PICKER_DIALOG: 
            return showDatePicker();
        case TIME_PICKER_DIALOG: 
            return showTimePicker(); 
    }
    return super.onCreateDialog(id);
}

private DatePickerDialog showDatePicker() {


    DatePickerDialog datePicker = new DatePickerDialog
(ReminderEditActivity.this,new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mCalendar.set(Calendar.YEAR, year);
            mCalendar.set(Calendar.MONTH, monthOfYear);
            mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateDateButtonText(); 
        }
   }, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH),mCalendar.getCalendar.DAY_OF_MONTH)); 
    return datePicker; 
}


private void registerButtonListenersAndSetDefaultText() {

    mDateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(DATE_PICKER_DIALOG);  
        }
    }); 



    mConfirmButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            saveState(); 
            setResult(RESULT_OK);
            Toast.makeText(ReminderEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
            finish(); 
        }

    });

      updateDateButtonText(); 
      updateTimeButtonText();
}

}
4

1 に答える 1

0

日付と時刻のピッカーを削除し、代わりにスピナーを使用して薬を選択します。

スピナーの getSelectedItem() を使用して、選択した薬を取得します。選択した薬に基づいて、リマインダー間隔を見つけます。最後に、Calendar.add() を使用して現在の日付に間隔を追加し、リマインダーの日付を取得します。

于 2013-04-16T17:39:42.773 に答える