本文整理汇总了Java中android.widget.DatePicker.setMaxDate方法的典型用法代码示例。如果您正苦于以下问题:Java DatePicker.setMaxDate方法的具体用法?Java DatePicker.setMaxDate怎么用?Java DatePicker.setMaxDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.DatePicker
的用法示例。
在下文中一共展示了DatePicker.setMaxDate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateDialog
import android.widget.DatePicker; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog dialog = new DatePickerDialog(getActivity(),
R.style.CustomDatePickerDialogTheme, this, mParent.mYear, mParent.mMonth, 1);
DatePicker datePicker = dialog.getDatePicker();
// Limit range.
Calendar c = mParent.getCalendar();
datePicker.setMinDate(c.getTimeInMillis());
c.set(Calendar.YEAR, mParent.mYear + CC_EXP_YEARS_COUNT - 1);
datePicker.setMaxDate(c.getTimeInMillis());
// Remove day.
datePicker.findViewById(getResources().getIdentifier("day", "id", "android"))
.setVisibility(View.GONE);
return dialog;
}
开发者ID:googlesamples,项目名称:android-AutofillFramework,代码行数:19,代码来源:CreditCardExpirationDatePickerView.java
示例2: onCreateContentView
import android.widget.DatePicker; //导入方法依赖的package包/类
@Override
protected View onCreateContentView(Bundle savedInstanceState) {
picker = new DatePicker(getContext());
Calendar c = Calendar.getInstance();
if (savedInstanceState != null){
c.setTimeInMillis(savedInstanceState.getLong(DATE));
} else if (getArguments().containsKey(DATE)) {
c.setTimeInMillis(getArguments().getLong(DATE));
}
picker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);
if (getArguments().containsKey(MIN_DATE)) {
picker.setMinDate(getArguments().getLong(MIN_DATE));
}
if (getArguments().containsKey(MAX_DATE)) {
picker.setMaxDate(getArguments().getLong(MAX_DATE));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& getArguments().containsKey(FIRST_DAY_OF_WEEK)) {
picker.setFirstDayOfWeek(getArguments().getInt(FIRST_DAY_OF_WEEK));
}
return picker;
}
示例3: createDialog
import android.widget.DatePicker; //导入方法依赖的package包/类
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;
}