Code example for DatePickerDialog

Methods: setTitle, setOnDismissListener, show

0
 
	@Override 
	public void onClick(final View v) {
		Calendar calendar = getTimeOrNow(editText);
 
		DatePickerDialog d = new DatePickerDialog(context,
				new OnDateSetListener() {
 
					@Override 
					public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
						editText.setText(String.format("%02d.%02d.%04d", dayOfMonth, monthOfYear + 1, year));
						editText.setError(null);
					} 
				}, 
				calendar.get(Calendar.YEAR),
				calendar.get(Calendar.MONTH),
				calendar.get(Calendar.DAY_OF_MONTH));
		d.setOnDismissListener(new OnDismissListener() {
 
			@Override 
			public void onDismiss(DialogInterface dialog) {
				next.requestFocus();
 
				new Handler().post(new Runnable() {
 
					@Override 
					public void run() { 
						inputManager.showSoftInput(next, 0);
					} 
				}); 
			} 
		}); 
		d.setTitle("Дата рождения");
		d.show();
	} 
 
	public static Calendar getTimeOrNow(TextView textView) {
		Calendar calendar = GregorianCalendar.getInstance();
		Matcher m = DATE_PATTERN.matcher(textView.getText());