There is a problem with both DatePickerDialog and TimePickerDialog. A user can select a date and a time with the plus or minus buttons. This works. But when the user clicks into the field, he can set a value by keyboard:
But this does not work at all. When the user types in a new value, and clicks the "OK" button, the value of the currently selected field will not be passed to the onDateSet
method. This works neither in DatePickerDialog
nor in TimePickerDialog
. Instead the user needs to click the green forward button on the keyboard to really set the value in the DatePickerDialog
. When he presses "OK" then, the value is passed, but this is a pretty idiotic usability. Nobody would do this. This is how I implement the fragments:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{
private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int month, int day)
{
final Calendar calendar = Calendar.getInstance(Locale.getDefault());
calendar.set(year, month, day);
String pickedDate = dateFormat.format(calendar.getTime());
((MenuEditActivity)getActivity()).setMenuDate(pickedDate);
}
@Override
public void onCancel(DialogInterface dialog)
{
super.onCancel(dialog);
}
}
Did anybody have the same issue and already implement some quick workaround? (I'd rather not want to reimplement the whole Picker dialogs, just of this half-baked implementation).