我已经有一个DatePicker,当用户单击EditText字段时,它将弹出
eReminderDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//To show current date in the datepicker
Calendar mcurrentDate = Calendar.getInstance();
int mYear = mcurrentDate.get(Calendar.YEAR);
int mMonth = mcurrentDate.get(Calendar.MONTH);
int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker;
mDatePicker = new DatePickerDialog(AddReminder.this, new OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/* Your code to get date and time */
selectedmonth = selectedmonth + 1;
eReminderDate.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Select Date");
mDatePicker.show();
}
});
我尝试以类似的方式进行TimePicker,但无法使其正常工作。这是我尝试使其工作的尝试
eReminderTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(AddReminder.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
eReminderTime.setText( ""selectedHour + ":" + selectedMinute);
}
}, hour, minute);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
是否有可能像我为DatePicker所做的那样做呢?
我什至尝试使用此代码单击EditText字段后甚至弹出一个TimePicker。
eReminderTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(TIME_DIALOG_ID);
}
});
由于某种原因,当我将其输入Android Studio时,“ showDialog”被打分。
谁能给我有关我要去哪里的提示?还是我只需要使用自定义DialogFragment?