我有这段代码,我可以在其中一次从日期选择器和时间选择器中设置时间和日期:
private void dialoguetime() {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialogue);
dialog.setCancelable(true);
dialog.setTitle("This is Dialog 1");
dialog.show();
TimePicker time_picker = (TimePicker) dialog
.findViewById(R.id.timePicker1);
hours = time_picker.getCurrentHour();
minute = time_picker.getCurrentMinute();
time_picker.setOnTimeChangedListener(new OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay,
int minutes) {
// TODO Auto-generated method stub
// Toast.makeText(CustomDialog.this,
// "hourOfDay = "+hourOfDay+"minute = "+minute , 1000).show();
hours = hourOfDay;
minute = minutes;
}
});
final DatePicker date_picker = (DatePicker) dialog
.findViewById(R.id.datePicker1);
Button btn = (Button) dialog.findViewById(R.id.button2);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
xDate = date_picker.getYear() + "-"+ (date_picker.getMonth() + 1) + "-"+ date_picker.getDayOfMonth() + " " + hours+ ":" + minute + ":00";
Toast.makeText(
getApplicationContext(),
xDate, Toast.LENGTH_LONG)
.show();
dialog.cancel();
}
}
);
}
从这里我可以得到一个像这样的日期格式的字符串yyyy-mm-dd hh:mm:ss
,现在我想向该选定时间的用户发出警报(作为警报)。我为此使用了警报管理器,但它不允许我选择那个日期?
我怎样才能做到这一点?