Code example for DatePicker

Methods: initsetCalendarViewShown

0
public class DatePickerPreference extends DialogPreference implements OnDateChangedListener, OnDateSetListener {
 
	@SuppressLint("NewApi") 
	@Override 
	protected View onCreateDialogView() {
		DatePicker picker = new DatePicker(getContext());
		strDate = getPersistedString(null);
		LocalDate startDate;
		try { 
			startDate = strDate == null ? new LocalDate() : fmt.parseLocalDate(strDate);
		} catch (IllegalFieldValueException e) {
			startDate = new LocalDate();
		} 
 
		if (android.os.Build.VERSION.SDK_INT >= 11) {
			picker.setCalendarViewShown(false);
		} 
		picker.init(startDate.getYear(), startDate.getMonthOfYear() - 1, startDate.getDayOfMonth(), this);
		return picker;
	} 
 
	public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
		strDate = String.format("%4d-%02d-%02d", year, monthOfYear + 1, dayOfMonth);