@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Find the TaskEditFragment that created this dialog by name. // We'll use that fragment as the edit callback, // so that when the user chooses a new date in our datepicker // dialog, the dialog will call back into the edit fragment to // set the new date. OnDateSetListener callback = (OnDateSetListener) getFragmentManager() .findFragmentByTag (TaskEditFragment .DEFAULT_FRAGMENT_TAG); // Construct a new DatePicker dialog that will be hosted by // this fragment. Set its Year, Month, and Day to the values // specified in the args bundle Bundle args = getArguments(); return new DatePickerDialog(getActivity(), callback, args.getInt(YEAR), args.getInt(MONTH), args.getInt(DAY)); }
private void setBtn_chaxunClickListener(View view) { DatePickerDialog dpd = new MyPickerDialog(MainActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int year, int month, int day) { String data = year + "年" + (month + 1) + "月"; tv_curYearMonth.setText(data); list = aDao.selectByData(data); setAdapter(); jisuan(); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dpd.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(); }
/** * �������� : getEndDate �������� : ����������ֵ˵���� * * @param etEndDate2 * * �ļ�¼�� ���� ��2015��10��30�� ����5:48:49 ���ˣ�hxf ���� �� * */ protected void getEndDate() { // TODO Auto-generated method stub new DatePickerDialog(ManagerCountActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String month = String.valueOf(monthOfYear + 1); String day = String.valueOf(dayOfMonth); if (dayOfMonth >= 1 && dayOfMonth <= 9) { day = "0" + day; } if (monthOfYear >= 0 && monthOfYear <= 8) { month = "0" + month; } etEndDate.setText(year + "-" + month + "-" + day); } }, year, monthOfYear, dayOfMonth).show(); }
/** * �������� : getBeginDate �������� : ����������ֵ˵���� * * @param etBeginDate2 * * �ļ�¼�� ���� ��2015��10��30�� ����5:48:49 ���ˣ�hxf ���� �� * */ protected void getBeginDate() { // TODO Auto-generated method stub // ʹ��DatePickerDialog�Ի�������ʹ�������ڲ��ʽ����һ�����ڶԻ��� new DatePickerDialog(ManagerCountActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String month = String.valueOf(monthOfYear + 1); String day = String.valueOf(dayOfMonth); if (dayOfMonth >= 1 && dayOfMonth <= 9) { day = "0" + day; } if (monthOfYear >= 0 && monthOfYear <= 8) { month = "0" + month; } etBeginDate.setText(year + "-" + month + "-" + day); } }, year, monthOfYear, dayOfMonth).show();// ���������������ڶԻ����ʼ��ʱ���õ�ʱ�䣬���һ��Ҫ����show�������� }
private OnDateSetListener createDateSetListener() { OnDateSetListener listener = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) { final FragmentActivity act = getActivity(); if(!isDetached() && !isRemoving() && act != null) { act.runOnUiThread(new Runnable() { DateFormat df = new SimpleDateFormat("cc, dd.MM.yyyy", Locale.GERMANY); @Override public void run() { controller.setDate(year, monthOfYear, dayOfMonth); String title = act.getString(R.string.title_activity_attendance) + " " + df.format(controller.getAttendanceDate().getTime()); txtTitle.setText(title); refreshList(); } }); } } }; return listener ; }
public void onBirthdayClick(View view) { if (mDatePickerDialog == null) { mDatePickerDialog = new DatePickerDialog(RegisterActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub mBirthdayEditText.setText(String.format( "%04d-%02d-%02d", year, monthOfYear + 1, dayOfMonth)); mCalendar.set(Calendar.YEAR, year); mCalendar.set(Calendar.MONTH, monthOfYear); mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); } }, 1980, 0, 1); mCalendar.set(Calendar.YEAR, 1980); mCalendar.set(Calendar.MONTH, 0); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDatePickerDialog.setCanceledOnTouchOutside(true); mDatePickerDialog .setTitle(getString(R.string.str_hint_select_birthday)); } mDatePickerDialog.show(); }
private void setDateTimeField() { edt_birthday.setOnFocusChangeListener(this); Calendar newCalendar = Calendar.getInstance(); BirthdayDatePickerDialog = new DatePickerDialog(this, R.style.DatePickerStyle, new OnDateSetListener() { // BirthdayDatePickerDialog = new DatePickerDialog(this, new OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar newDate = Calendar.getInstance(); newDate.set(year, monthOfYear, dayOfMonth); edt_birthday.setText(dateFormatter.format(newDate.getTime())); } },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.WEEK_OF_MONTH), newCalendar.get(Calendar.DAY_OF_MONTH)); BirthdayDatePickerDialog.setTitle(""); }
public void selectDateFrom() { DatePickerFragment dialog = new DatePickerFragment(); if(dateFrom != null) { Bundle args = new Bundle(1); args.putLong(DatePickerFragment.ARG_INITIAL_DATE, dateFrom.getTime()); dialog.setArguments(args); } dialog.setListener(new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { dateFrom = DateUtils.getDate(year, monthOfYear, dayOfMonth).getTime(); refreshButtons(); refreshAnalysis(); } }); dialog.show(getFragmentManager(), "datePicker"); }
public void selectDateTo() { DatePickerFragment dialog = new DatePickerFragment(); if(dateTo != null) { Bundle args = new Bundle(1); args.putLong(DatePickerFragment.ARG_INITIAL_DATE, dateTo.getTime()); dialog.setArguments(args); } dialog.setListener(new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { dateTo = DateUtils.getDate(year, monthOfYear, dayOfMonth).getTime(); refreshButtons(); refreshAnalysis(); } }); dialog.show(getFragmentManager(), "datePicker"); }
public void showDatePickerDialog(View v, String tag, final EditText dateEditText, final int[] dateStrings) { DatePickerFragment datePicker = new DatePickerFragment(); Calendar calender = Calendar.getInstance(); Bundle args = new Bundle(); args.putInt("year", calender.get(Calendar.YEAR)); args.putInt("month", calender.get(Calendar.MONTH)); args.putInt("day", calender.get(Calendar.DAY_OF_MONTH)); datePicker.setArguments(args); OnDateSetListener ondate = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int day) { dateEditText.setText(day + "/" + (month + 1) + "/" + year); dateStrings[0] = year; dateStrings[1] = month + 1; dateStrings[2] = day; } }; datePicker.setCallBack(ondate); datePicker.show(getFragmentManager(), tag); }
public void showDatePickerDialog(View v, String tag, final EditText dateEditText, final int[] date) { DatePickerFragment datePicker = new DatePickerFragment(); Calendar calender = Calendar.getInstance(); Bundle args = new Bundle(); args.putInt("year", calender.get(Calendar.YEAR)); args.putInt("month", calender.get(Calendar.MONTH)); args.putInt("day", calender.get(Calendar.DAY_OF_MONTH)); datePicker.setArguments(args); OnDateSetListener ondate = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int day) { dateEditText.setText(day + "/" + (month + 1) + "/" + year); date[0] = year; date[1] = month + 1; date[2] = day; } }; datePicker.setCallBack(ondate); datePicker.show(getFragmentManager(), tag); }
@Override protected AlertDialog createDialog(final Calendar cal) { OnDateSetListener callback = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, monthOfYear); cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); listener.onValuePicked(String.valueOf(cal.getTimeInMillis())); } }; DatePickerDialog dialog = new DatePickerDialog(activity, callback, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); return dialog; }
/** * 日期和时间选择对话框,选选择日期后选择时间 * * @param con 上下文 * @param title1 日期选择标题 * @param title2 事件选择标题 * @param calendar 默认日期 * @param listener 时间选择事件 */ public static void pickDateTime(final Context con, String title1, final String title2, final Calendar calendar, final OnTimeSetListener listener) { // 增加判断,解决4.X系统可能存在的弹出多个时间选择器的问题 final boolean[] isShowTime = {false}; pickDate(con, title1, calendar, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { calendar.set(year, month, dayOfMonth); if (!isShowTime[0]) { isShowTime[0] = true; pickTime(con, title2, calendar, listener); } } }); }
/** * 年月选择对话框 * * @param con * @param title * @param calendar * @param listener */ public static void pickMonth(Context con, String title, Calendar calendar, final OnDateSetListener listener) { LinearLayout ll = new LinearLayout(con); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); ll.setLayoutParams(layoutParams); ll.setOrientation(LinearLayout.VERTICAL); //添加一条线 LinearLayout line = new LinearLayout(con); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1); line.setBackgroundColor(con.getResources().getColor(R.color.line)); line.setLayoutParams(lp); ll.addView(line); //添加选择器控件 final DatePicker datePicker = new DatePicker(con, null, themeId); datePicker.setLayoutParams(layoutParams); datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null); datePicker.setCalendarViewShown(false); ll.addView(datePicker); //初始化对话框 QuickDialog.Builder builder = new QuickDialog.Builder(con); builder.setContentView(ll); builder.setTitle(title); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); listener.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); } }); builder.create().show(); }
/** * OnClick listener for date text view */ public void onClickDatePicker(View view) { new DatePickerDialog(EditExpenseActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int y, int m, int d) { Calendar serviceDate = Calendar.getInstance(); serviceDate.set(y, m, d); setExpenseDate(serviceDate); } }, expenseDate.get(Calendar.YEAR), expenseDate.get(Calendar.MONTH), expenseDate.get(Calendar.DAY_OF_MONTH)).show(); }
@Override protected void onClick(View v, int id) { new DatePickerDialog(activity, new OnDateSetListener(){ @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, monthOfYear); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); onDateText.setText(DateUtils.getMediumDateFormat(activity).format(c.getTime())); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show(); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState){ OnDateSetListener callback = (OnDateSetListener) getFragmentManager().findFragmentByTag(TaskEditFragment.DEFAULT_FRAGMENT_TAG); Bundle args = getArguments(); return new DatePickerDialog(getActivity(),callback,args.getInt(YEAR),args.getInt(MONTH),args.getInt(DAY)); }
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (getArguments().containsKey(DEFAULT_DATE)) { this.defaultDate = getArguments().getLong(DEFAULT_DATE); } try { mListener = (OnDateSetListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnDateSetListener"); } }
/** * Show date and time pickers */ protected void showDateTimeSelectors(long reminder) { // Sets actual time or previously saved in note final Calendar now = DateHelper.getCalendar(reminder); DatePickerDialog mCalendarDatePickerDialog = DatePickerDialog.newInstance( new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { reminderYear = year; reminderMonth = monthOfYear; reminderDay = dayOfMonth; TimePickerDialog mRadialTimePickerDialog = TimePickerDialog.newInstance( new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) { hourOfDay = hour; minutes = minute; showRecurrencePickerDialog(recurrenceRule); } }, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), DateHelper.is24HourMode(mActivity)); mRadialTimePickerDialog.show(mActivity.getSupportFragmentManager(), Constants.TAG); } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); mCalendarDatePickerDialog.show(mActivity.getSupportFragmentManager(), Constants.TAG); }
private void setBtn_dataClickListener(View view) { DatePickerDialog dpd = new DatePickerDialog(MainActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker p, int year, int month, int day) { btn_data.setText(year + "年" + (month + 1) + "月" + day + "日"); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dpd.show(); }
private void showDatePickerDialog() { final OnDateSetListener onDateSetListener = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); String stringDate = (new SimpleDateFormat(DATE_FORMAT, Locale.US)) .format(calendar.getTime()); String newValue = String.format(Locale.getDefault(), "%s: %s", getString(R.string.report_date), stringDate); textViewReportDate.setText(newValue); DateTime currentDateTime = DateTime.now(); DateTime selectedDateTime = DateTime.parse(stringDate); /* * in case when user selected today's date, we need to know about time as well. * selectedDateTime does not contain time information (only date), that's why we * need to create a new DateTime object by calling DateTime.now() */ DateTime dateTime; if (DateTimeComparator.getDateOnlyInstance() .compare(currentDateTime, selectedDateTime) == 0) { dateTime = currentDateTime; } else { dateTime = selectedDateTime; } formSectionPresenter.saveEventDate(getEventUid(), dateTime); } }; DatePickerDialogFragment datePickerDialogFragment = DatePickerDialogFragment.newInstance(false); datePickerDialogFragment.setOnDateSetListener(onDateSetListener); datePickerDialogFragment.show(getSupportFragmentManager()); }
public void showDatePicker(OnDateSetListener dateSetListener, int year, int month, int day) { if (mActivity.isFinishing()) { return; } close(); dlgDate = new DatePickerDialog(mActivity, dateSetListener, year, month, day); dlgDate.show(); // DialogFragment datePicker = new DatePickerFragment(dateSetListener, year, month, day); // try { // datePicker.show(mActivity.getSupportFragmentManager(), "datePicker"); // } catch (Exception e) { // Log.e(TAG, "showDatePicker " + e.getMessage()); // } }
private Dialog createDatePicker() { OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { setDate(year, monthOfYear, dayOfMonth); Log.d(TAG, "Setting date to: " + year + "-" + monthOfYear + "-" + dayOfMonth); } }; return new DatePickerDialog(getContext(), dateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)) { }; }
public static void ShowDateDialog(Context context,String message,OnDateSetListener listener) { Calendar c=Calendar.getInstance(); int y=c.get(Calendar.YEAR); int m=c.get(Calendar.MONTH); int d=c.get(Calendar.DAY_OF_MONTH); DatePickerDialog dlg=new DatePickerDialog(context, listener, y, m, d); //dlg.setOnCancelListener(cancelListener); //dlg.setMessage(message); dlg.setTitle(message); dlg.show(); }
public static DatePickerFragment newInstance(Calendar date, OnDateSetListener onDateSetListener) { DatePickerFragment pickerFragment = new DatePickerFragment(); pickerFragment.setOnDateSetListener(onDateSetListener); //Pass the date in a bundle. Bundle bundle = new Bundle(); bundle.putSerializable("SELECTED_DATE", date); pickerFragment.setArguments(bundle); return pickerFragment; }
private OnDateSetListener createDateSetListener() { OnDateSetListener l = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { controller.setBirthdate(year, monthOfYear, dayOfMonth); } }; return l; }
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Verify that the host activity implements the callback interface try { // Instantiate the NoticeDialogListener so we can send events to the host mListener = (OnDateSetListener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception throw new ClassCastException(activity.toString() + " must implement OnDateSetListener"); } }
@Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = (Activity)activity; if (getArguments().containsKey(DEFAULT_DATE)) { this.defaultDate = getArguments().getLong(DEFAULT_DATE); } try { mListener = (OnDateSetListener) mActivity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnDateSetListener"); } }
@JavascriptInterface public void chooseDate(String date, final String eleId) { String[] dateParts = date.split("-"); new DatePickerDialog( MainActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // Toast.makeText(MainActivity.this, // year + "-" + monthOfYear + "-" + dayOfMonth, 0) // .show(); String dateString = year + "-" + ((monthOfYear + 1) < 10 ? "0" + (monthOfYear + 1) : (monthOfYear + 1)) + "-" + (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth); // 不支持非UI线程调用 // wv.loadUrl("javascript:setDate(" + dateString + // "," + eleId // + ")"); Message msg = new Message(); Bundle bundle = new Bundle(); bundle.putString("dateString", dateString); bundle.putString("eleId", eleId); msg.setData(bundle); handler.sendMessage(msg); } }, Integer.parseInt(dateParts[0]), Integer.parseInt(dateParts[1]) - 1, Integer .parseInt(dateParts[2])).show(); }
private void showDatePickerDialog(final Context context, final EditText editText) { // don't show dialog again if it's already being shown if (datePickerDialog == null) { Date date = (Date)getModel().getValue(getName()); if (date == null) { date = new Date(); } Calendar calendar = Calendar.getInstance(Locale.getDefault()); calendar.setTimeZone(timeZone); calendar.setTime(date); datePickerDialog = new DatePickerDialog(context, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(Locale.getDefault()); calendar.setTimeZone(timeZone); calendar.set(year, monthOfYear, dayOfMonth); getModel().setValue(getName(), calendar.getTime()); editText.setText(displayFormat.format(calendar.getTime())); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); datePickerDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { datePickerDialog = null; } }); datePickerDialog.show(); } }
public static void pickDate(Context con, String title, OnDateSetListener listener) { Calendar calendar = Calendar.getInstance(); pickDate(con, title, calendar, listener); }
public static void pickDate(Context con, OnDateSetListener listener) { pickDate(con, con.getString(R.string.pick_date), listener); }