本文整理汇总了Java中com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener方法的典型用法代码示例。如果您正苦于以下问题:Java DatePickerDialog.OnDateSetListener方法的具体用法?Java DatePickerDialog.OnDateSetListener怎么用?Java DatePickerDialog.OnDateSetListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.wdullaer.materialdatetimepicker.date.DatePickerDialog
的用法示例。
在下文中一共展示了DatePickerDialog.OnDateSetListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDialog
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; //导入方法依赖的package包/类
/**
* Creates a {@link DatePickerDialog} instance with the <code>localDate</code> selected.
*
* @param localDate the selected start localDate
* @param listener to be triggered when the user selects a localDate
* @param clock to get the current date
* @return the {@link DatePickerDialog} created instance
*/
@NonNull
public static DatePickerDialog createDialog(@Nullable LocalDate localDate, @Nullable Consumer<LocalDate> listener,
@NonNull Clock clock) {
localDate = Optional.ofNullable(localDate)
.orElse(LocalDate.now(clock));
DatePickerDialog.OnDateSetListener dialogCallBack = (view, year, monthOfYear, dayOfMonth) -> {
LocalDate date = LocalDate.of(year, monthOfYear + 1, dayOfMonth);
Optional.ofNullable(listener)
.ifPresent(theListener -> theListener.accept(date));
};
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
dialogCallBack,
localDate.getYear(),
localDate.getMonthValue() - 1,
localDate.getDayOfMonth()
);
datePickerDialog.dismissOnPause(true);
return datePickerDialog;
}
示例2: showDatePicker
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; //导入方法依赖的package包/类
/**
* Show the date picker
*/
private void showDatePicker(final EditText birthdayEditText) {
DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
/**
* Handle selected time for birthday
* @param view - the current view
* @param year - the selected year
* @param monthOfYear - the selected month
* @param dayOfMonth - the selected day
*/
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
mBirthday.set(year, monthOfYear, dayOfMonth);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
birthdayEditText.setText(dateFormat.format(mBirthday.getTime()));
}
};
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(listener,
mBirthday.get(Calendar.YEAR), mBirthday.get(Calendar.MONTH),
mBirthday.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setVersion(DatePickerDialog.Version.VERSION_2);
datePickerDialog.setTitle(getActivity().getString(R.string.set_birthday));
datePickerDialog.vibrate(false);
datePickerDialog.dismissOnPause(true);
datePickerDialog.setOnDateSetListener(listener);
datePickerDialog.show(getActivity().getFragmentManager(), "date_picker");
}
示例3: showDatePicker
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; //导入方法依赖的package包/类
public static void showDatePicker(Activity activity,
DatePickerDialog.OnDateSetListener setListener) {
Calendar now = Calendar.getInstance();
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
setListener,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
datePickerDialog.setThemeDark(true);
datePickerDialog.show(activity.getFragmentManager(), TAG_DATE_PICKER);
}