我正在尝试为将来的日期禁用日期选择器,但不知道...
这是我尝试过的:
bday.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar mcurrentDate=Calendar.getInstance();
year=mcurrentDate.get(Calendar.YEAR);
month=mcurrentDate.get(Calendar.MONTH);
day=mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker =new DatePickerDialog(CreateAccountActivity.this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday)
{
year = selectedyear;
month = selectedmonth;
day = selectedday;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
String currenttime = new String(dateFormat.format(cal.getTime()));
String selectedtime = new String (new StringBuilder().append(year).append("-").append(month+1).append("-").append(day));
String futuretime = new String (dateFormat.format(System.currentTimeMillis()));
if(selectedtime==currenttime)
{
Toast.makeText(getApplicationContext(), "you were not born in the future", Toast.LENGTH_SHORT).show();
bday.setText("");
}
else
{
bday.setText(new StringBuilder().append(year).append("-").append(month+1).append("-").append(day));
}}
},year, month, day);
mDatePicker.setTitle("Please select date");
mDatePicker.show();
}
});
建议使用Stackoverflow:
mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
但在上述情况下,我应该如何使用呢?我正在尝试禁用将来的日期。但没有任何想法:(
声明监听器 DatePicker
使用后mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句