DatePickerDialog dpd = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { } }, 2015, 5, 22); dpd.show();
public void chooseDate(View v) { new DatePickerDialog(this, d, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)) .show(); }
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClickButton(View v) { DatePickerDialog d = new DatePickerDialog(this, null, 2014, 5, 4); d.show(); } }
Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 1); final DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { boolean fired = false; public void onDateSet(final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) { Log.i("PEW PEW", "Double fire check"); if (fired == true) { Log.i("PEW PEW", "Double fire occured. Silently-ish returning"); return; } else { //first time fired fired = true; } //Normal date picking logic goes here } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); dateDialog.show();
DatePickerDialog picker = new DatePickerDialog( this, null, // instead of a listener 2012, 6, 15); picker.setCancelable(true); picker.setCanceledOnTouchOutside(true); picker.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("Picker", "Correct behavior!"); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("Picker", "Cancel!"); } }); picker.show();
now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) ).show(); });
public static void showDatePickerDialog( Context context, CalendarDay day, DatePickerDialog.OnDateSetListener callback) { if (day == null) { day = CalendarDay.today(); } DatePickerDialog dialog = new DatePickerDialog( context, 0, callback, day.getYear(), day.getMonth() - 1, day.getDay() ); dialog.show(); }
class MyClass implements OnClickListener, OnDateSetListener { EditText editText; this.editText = (EditText) findViewById(R.id.editText); this.editText.setOnClickListener(this); @Override public void onClick(View v) { DatePickerDialog dialog = new DatePickerDialog(this, this, 2013, 2, 18); dialog.show(); } @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // this.editText.setText(); } }
/** * use to show datepicker * * @param mContext * @param format of the date format * @param mTextView in which you have to set selected date */ public static void showDatePickerDialog(final Context mContext, final String format, final TextView mTextView) { new DatePickerDialog(mContext, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { SimpleDateFormat dateFormatter = new SimpleDateFormat(format); dateTime.set(year, monthOfYear, dayOfMonth); mTextView.setText(dateFormatter.format(dateTime.getTime())); } }, dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH), dateTime.get(Calendar.DAY_OF_MONTH)).show(); }
/** * use to show datepicker * * @param mContext * @param format of the date format * @param mTextView in which you have to set selected date */ public static void showDatePickerDialog(final Context mContext, final String format, final TextView mTextView) { new DatePickerDialog(mContext, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { SimpleDateFormat dateFormatter = new SimpleDateFormat(format); dateTime.set(year, monthOfYear, dayOfMonth); mTextView.setText(dateFormatter.format(dateTime.getTime())); } }, dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH), dateTime.get(Calendar.DAY_OF_MONTH)).show(); }
dialog.show();
@OnClick(R.id.alarm_date) void openDatePicker() { getDatePickerDialog(); mDataPicker.show(); }
@Override public void onClick(View v) { Calendar cal = Calendar.getInstance(); cal.setTime(birthday); DatePickerDialog datePicker = new DatePickerDialog( context, birthdayPickerListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); datePicker.show(); } });
@Override public void onClick(View v) { Calendar cal = Calendar.getInstance(); cal.setTime(goal_date); DatePickerDialog datePicker = new DatePickerDialog( context, goalDatePickerListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); datePicker.show(); } });
Calendar calendar=Calendar.getInstance(); DatePickerDialog dialog=new DatePickerDialog(this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //your code } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dialog.getDatePicker().setMinDate(calendar.getTimeInMillis()); dialog.show();
@OnClick(R.id.et_dob) public void onClickDOB() { new DatePickerDialog(getContext(), date, myCalendar .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); }
public void onClick(View view) { switch (view.getId()) { case R.id.btnDatePicker: new DatePickerDialog(this, this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show(); break; case R.id.btnTimePicker: new TimePickerDialog(this, this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show(); break; } }
@Override public void onCellSelected() { super.onCellSelected(); DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); datePickerDialog.show(); }
private void showDatePicker() { Calendar c = Calendar.getInstance(); c.setTime(adapter.getDateForPosition(viewPager.getCurrentItem()) .toDate()); DatePickerDialog dialog = new DatePickerDialog(this, dilbertOnDateSetListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); dialog.show(); }
DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { } },2016,10,15); datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis()+1000*60*60*24*5); datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()-1000*60*60*24*5); datePickerDialog.show();