Best code examples for Android DatePicker class (android.widget.DatePicker)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DatePicker class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android DatePicker examples from Open Source projects
This code example shows how to use the following methods: getDayOfMonth, getMonth, getYear, setMaxDate, setMinDate
     if (max <= min) {
         return; 
     } 
     Calendar minCal = trimToDate(min);
     Calendar maxCal = trimToDate(max);
     int currentYear = picker.getYear();
     int currentMonth = picker.getMonth();
     int currentDayOfMonth =  picker.getDayOfMonth();
     picker.updateDate(maxCal.get(Calendar.YEAR),
             maxCal.get(Calendar.MONTH),
             maxCal.get(Calendar.DAY_OF_MONTH));
     picker.setMinDate(minCal.getTimeInMillis());
     picker.updateDate(minCal.get(Calendar.YEAR),
             minCal.get(Calendar.MONTH),
             minCal.get(Calendar.DAY_OF_MONTH));
     picker.setMaxDate(maxCal.getTimeInMillis());
 
     // Restore the current date, this will keep the min/max settings 
     // previously set into account. 
     picker.updateDate(currentYear, currentMonth, currentDayOfMonth);

8
CodeRank
This code example shows how to use the following methods: getDayOfMonth, getMonth, getYear
	} 
 
	@Override 
	protected void onDialogClosed(final boolean positiveResult) {
		if (positiveResult) {
			this.v.set(this.dp.getYear(), this.dp.getMonth(), this.dp.getDayOfMonth());
			this.cv.put(this.getKey(), this.v.getTimeInMillis());
			if (this.ul != null) {
				this.ul.onUpdateValue(this);
			} 
			if (this.dt) {
				TimePickerDialog tpd = new TimePickerDialog(this.getContext(), this,
						this.v.get(Calendar.HOUR_OF_DAY), this.v.get(Calendar.MINUTE), true);
				tpd.setTitle(this.getTitle());
				tpd.setCancelable(true);
				tpd.show();
			} 
		} 
	} 
 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: clearFocus, getDayOfMonth, getMonth, getYear
        tryNotifyDateTimeSet(); 
    } 
 
    private void tryNotifyDateTimeSet() { 
        if (mCallBack != null) {
            mDatePicker.clearFocus();
            mCallBack.onDateTimeSet(mDatePicker, mTimePicker, mDatePicker.getYear(),
                    mDatePicker.getMonth(), mDatePicker.getDayOfMonth(),
                    mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
        } 
    } 
 
    @Override 
    protected void onStop() { 
        if (Build.VERSION.SDK_INT >= 16) {
            // The default behavior of dialogs changed in JellyBean and onwards. 
            // Dismissing a dialog (by pressing back for example) 
            // applies the chosen date. This code is added here so that the custom 
            // pickers behave the same as the internal DatePickerDialog. 
            tryNotifyDateTimeSet(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: clearFocus, getDayOfMonth, getMonth, getYear
			this.setButton(DialogInterface.BUTTON_POSITIVE, getContext().getText(android.R.string.ok), new DialogInterface.OnClickListener()
			{ 
				@Override 
				public void onClick(DialogInterface dialog, int which)
				{ 
					picker.clearFocus(); // focus must be cleared so the value change listener is called
					callback.onDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
				} 
			}); 
		} 
		catch(Exception e)
		{ 
			// reflection probably failed 
		} 
	} 
} 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getDayOfMonth, getMonth, getYear
		textView.setText( new SpannableStringBuilder( "foo" ) );
		assertEquals( "foo", androidWidgetBuilder.getValue( textView ) );
 
		// DatePicker 
 
		DatePicker datePicker = new DatePicker( null );
		Date date = new Date( 75, 4, 9 );
		androidWidgetBuilder.setValue( date, datePicker );
		assertEquals( 1975, datePicker.getYear() );
		assertEquals( 4, datePicker.getMonth() );
		assertEquals( 9, datePicker.getDayOfMonth() );
		assertEquals( 75, ( (Date) androidWidgetBuilder.getValue( datePicker ) ).getYear() );
		assertEquals( 4, ( (Date) androidWidgetBuilder.getValue( datePicker ) ).getMonth() );
		assertEquals( 9, ( (Date) androidWidgetBuilder.getValue( datePicker ) ).getDate() );
 
		// Spinner 
 
		Spinner spinner = new Spinner( null );
		List<String> lookupList = CollectionUtils.newArrayList( "foo", "bar", "baz" );
		spinner.setAdapter( new LookupArrayAdapter<String>( null, lookupList, null ) );
Full Snippet Info
7
CodeRank
Related Android DatePicker Questions & Answers:
Other Android DatePicker Examples
14:	    }
15:	
16:	    public void onDateSet(DatePicker view, int year, int month, int day) {
17:	        // Do something with the date chosen by the user
18:	    }

Read More

See Code Examples for Android DatePicker Methods: