在Android Date Picker中将SetMax日期设置为30天 [英] SetMax date to 30 days in Android Date Picker

查看:230
本文介绍了在Android Date Picker中将SetMax日期设置为30天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Datepicker 的材质设计库。我需要设置最小和最大日期。最小日期工作,但我无法从最小日期(当前日期)中获取应为30天的最大日期。任何人都知道如何使它在这里工作?

I'm using a Material design library for Datepicker. I need to set min and max date. The min date works but I am not able to get the max date which should be 30 days from the min date(current date). Can anyone know how to make it work here?

public void show() {
    Calendar now = Calendar.getInstance();
    DatePickerDialog dpd = DatePickerDialog.newInstance(
            PostInfo.this,
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH)
    );
    dpd.setMinDate(Calendar.getInstance());

    Calendar calendar = Calendar.getInstance(); 
  calendar.add(Calendar.DAY_OF_MONTH, 30);   


    dpd.setMaxDate(calendar.getInstance());


    dpd.show(getFragmentManager(), "Datepickerdialog");


推荐答案

您可以使用 setMaxDate )

Calendar calendar = Calendar.getInstance();  // this is default system date
dpd.setMinDate(calendar);                   // set today's date as min date
calendar.add(Calendar.DAY_OF_MONTH, 30);   // add date to 30 days later
dpd.setMaxDate(calendar);                 // set 30 days later as max date

这篇关于在Android Date Picker中将SetMax日期设置为30天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆