DatePicker的setMinDate()不起作用 [英] setMinDate() for DatePicker doesn't work
本文介绍了DatePicker的setMinDate()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DatePicker datepicker = (DatePicker) view.findViewById(R.id.ad_date_picker);
datepicker.setMinDate(Calendar.getInstance().getTimeInMillis());
它不工作。它只适用于xml( android:minDate =mm / dd / yyyy
),但我需要将动态的最小日期设置为当天。
我的最小API是11。
It just doesn't work. It works only in the xml (android:minDate="mm/dd/yyyy"
), but I need to set the minimum date dynamically to the current day.
My minimum API is 11.
推荐答案
PS:现在已经过时了。
P.S: Solution used to work before but might be outdated now.
尝试这样的东西。如果我理解正确,您希望将微调器的最小日期设置为今天的日期。它对我而言没有任何错误:
Try something like this. If I understand correctly, you wish to set the minimum date of spinner to today's date. It works for me without giving any error:
Calendar cal = Calendar.getInstance();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
long time = cal.getTimeInMillis();
DatePicker datepicker = (DatePicker) findViewById(R.id.datePicker);
datepicker.setMinDate(time);
在你的xml中,我假设你有这样的东西:
In your xml I am supposing that you have something like this:
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
这篇关于DatePicker的setMinDate()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文