android.app.DatePickerDialog.OnDateSetListener Java Examples
The following examples show how to use
android.app.DatePickerDialog.OnDateSetListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 日期和时间选择对话框,选选择日期后选择时间 * * @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); } } }); }
Example #2
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 年月选择对话框 * * @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(); }
Example #3
Source File: DatePickerFragmentActivity.java From coursera-android with MIT License | 5 votes |
@Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { ((OnDateSetListener) getActivity()).onDateSet(view, year, monthOfYear, dayOfMonth); }
Example #4
Source File: DatePickerFragmentActivity.java From coursera-android with MIT License | 5 votes |
@Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { ((OnDateSetListener) getActivity()).onDateSet(view, year, monthOfYear, dayOfMonth); }
Example #5
Source File: SupportDatePickerDialogFragment.java From react-native-GPay with MIT License | 4 votes |
void setOnDateSetListener(@Nullable OnDateSetListener onDateSetListener) { mOnDateSetListener = onDateSetListener; }
Example #6
Source File: DatePickerDialogFragment.java From react-native-GPay with MIT License | 4 votes |
static Dialog createDialog( Bundle args, Context activityContext, @Nullable OnDateSetListener onDateSetListener) { final Calendar c = Calendar.getInstance(); if (args != null && args.containsKey(DatePickerDialogModule.ARG_DATE)) { c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_DATE)); } final int year = c.get(Calendar.YEAR); final int month = c.get(Calendar.MONTH); final int day = c.get(Calendar.DAY_OF_MONTH); DatePickerMode mode = DatePickerMode.DEFAULT; if (args != null && args.getString(DatePickerDialogModule.ARG_MODE, null) != null) { mode = DatePickerMode.valueOf(args.getString(DatePickerDialogModule.ARG_MODE).toUpperCase(Locale.US)); } DatePickerDialog dialog = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { switch (mode) { case CALENDAR: dialog = new DismissableDatePickerDialog(activityContext, activityContext.getResources().getIdentifier("CalendarDatePickerDialog", "style", activityContext.getPackageName()), onDateSetListener, year, month, day); break; case SPINNER: dialog = new DismissableDatePickerDialog(activityContext, activityContext.getResources().getIdentifier("SpinnerDatePickerDialog", "style", activityContext.getPackageName()), onDateSetListener, year, month, day); break; case DEFAULT: dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); break; } } else { dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); switch (mode) { case CALENDAR: dialog.getDatePicker().setCalendarViewShown(true); dialog.getDatePicker().setSpinnersShown(false); break; case SPINNER: dialog.getDatePicker().setCalendarViewShown(false); break; } } final DatePicker datePicker = dialog.getDatePicker(); if (args != null && args.containsKey(DatePickerDialogModule.ARG_MINDATE)) { // Set minDate to the beginning of the day. We need this because of clowniness in datepicker // that causes it to throw an exception if minDate is greater than the internal timestamp // that it generates from the y/m/d passed in the constructor. c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MINDATE)); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); datePicker.setMinDate(c.getTimeInMillis()); } else { // This is to work around a bug in DatePickerDialog where it doesn't display a title showing // the date under certain conditions. datePicker.setMinDate(DEFAULT_MIN_DATE); } if (args != null && args.containsKey(DatePickerDialogModule.ARG_MAXDATE)) { // Set maxDate to the end of the day, same reason as for minDate. c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MAXDATE)); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); datePicker.setMaxDate(c.getTimeInMillis()); } return dialog; }
Example #7
Source File: DatePickerDialogFragment.java From react-native-GPay with MIT License | 4 votes |
void setOnDateSetListener(@Nullable OnDateSetListener onDateSetListener) { mOnDateSetListener = onDateSetListener; }
Example #8
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void pickDate(Context con, String title, OnDateSetListener listener) { Calendar calendar = Calendar.getInstance(); pickDate(con, title, calendar, listener); }
Example #9
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void pickDate(Context con, OnDateSetListener listener) { pickDate(con, con.getString(R.string.pick_date), listener); }
Example #10
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void pickDate(Context con, Calendar calendar, OnDateSetListener listener) { pickDate(con, con.getString(R.string.pick_date), calendar, listener); }
Example #11
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void pickMonth(Context con, Calendar calendar, OnDateSetListener listener) { pickMonth(con, "", calendar, listener); }
Example #12
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void pickMonth(Context con, OnDateSetListener listener) { Calendar calendar = Calendar.getInstance(); pickMonth(con, calendar, listener); }
Example #13
Source File: AddInfoAty.java From Huochexing12306 with Apache License 2.0 | 4 votes |
@Override public void onClick(View v) { Intent intent1 = new Intent(AddInfoAty.this, SelectAty.class); intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 不加此标志StationAty有时执行两次finish()才会返回。 intent1.putExtra(SelectAty.SEARCH_TYPE, SelectAty.SEARCH_STATION); switch (v.getId()) { case R.id.from: startActivityForResult(intent1, REQUEST_FROM_STATION); break; case R.id.to: startActivityForResult(intent1, REQUEST_TO_STATION); break; case R.id.trainNum: if (btnFrom.getText().length() == 0){ showMsg("请先选择出发地" + SF.TIP); }else if (btnTo.getText().length() == 0){ showMsg("请先选择目的地" + SF.TIP); }else if (!HttpUtil.isNetworkConnected(AddInfoAty.this)){ showMsg("无网络,无法取得车次列表" + SF.NO_NETWORK); }else{ intDataSource = DATA_FROM_MANUAL_REQUEST; getTrains(); } break; case R.id.btnDate: new DatePickerDialog(this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String tempDate = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth; try { Date date = TimeUtil.getDFormat().parse(tempDate); String preDate = intYear + "-" + (intMonth + 1) + "-" + (intDay-1); if (tempDate.compareTo(preDate)<0) { showMsg("最早可设置前一天以内的日期" + SF.FAIL); } else { tempDate = TimeUtil.getDFormat().format(date); etDate.setText(tempDate + " " + TimeUtil.getWeek(tempDate)); etDate.setTag(tempDate); } } catch (ParseException e) { e.printStackTrace(); } } }, intYear, intMonth, intDay).show(); break; case R.id.ok: addTravel(); break; } }
Example #14
Source File: DatePickerFragment.java From android-clean-sample-app with MIT License | 4 votes |
public void setListener(OnDateSetListener listener) { mListener = listener; }
Example #15
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * 日期选择对话框 * * @param con 上下文 * @param title 标题 * @param calendar 日期 * @param listener 选择事件 */ public static void pickDate(Context con, String title, Calendar calendar, OnDateSetListener listener) { pickMonth(con, title, calendar, listener); }