Android DatePicker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DatePicker class.

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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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) {
            tryNotifyDateTimeSet(); 
        } 
        super.onStop(); 
    } 
 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: clearFocus, getDayOfMonth, getMonth, getYear
    } 
 
    @Override 
    public void onClick(DialogInterface dialog, int which) {
        super.onClick(dialog, which);
        mDatePicker.clearFocus();
        onDateChanged(mDatePicker, mDatePicker.getYear(), mDatePicker.getMonth(),
                mDatePicker.getDayOfMonth());
        onDialogClosed(which == DialogInterface.BUTTON1);
    } 
 
    @Override 
    protected void onDialogClosed(boolean positiveResult) {
        if (!positiveResult) {
            sharedPreferences(); 
        } 
 
        super.onDialogClosed(positiveResult);
    } 
 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getDayOfMonth, getMonth, getYear
    private EditText mName;
    private EditText mDescription;
    private DatePicker mDate;
 
    private long getDateMillis() { 
        int year = mDate.getYear();
        int month = mDate.getMonth();
        int dayOfMonth = mDate.getDayOfMonth();
        Calendar c = Calendar.getInstance();
        c.set(year, month, dayOfMonth);
        return c.getTimeInMillis();
    } 
     
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_task); 
         
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getDayOfMonth, getMonth, getYear, init
		if (isDateAfter(view)) {
			textViewVisible(); 
			Calendar mCalendar = Calendar.getInstance();
			mCalendar.setFirstDayOfWeek(Calendar.MONDAY);
			if (color) {
				view.init(mCalendar.get(Calendar.YEAR),mCalendar.get(Calendar.MONTH),mCalendar.get(Calendar.DAY_OF_MONTH), this);
				color = false;
			} else { 
				view.init(year, month, day, null);
			} 
 
		} else { 
			textViewInvisible(); 
	        updateTitle(year, month, day);
		} 
    } 
 
    private void updateTitle(int year, int month, int day) {
        mCalendar.set(Calendar.YEAR, year);
        mCalendar.set(Calendar.MONTH, month);

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

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: