문제

I have implemented datepicker dialog in my app successfully, have doubt in disabling the dates, check it out my code

To get the year which is 13 year above the current year

 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

            String now = df.format(new java.util.Date());
            String[] datevalues = now.split("/");

            int yearsum = Integer.parseInt(datevalues[2]);
            int i;
            for (i = 0; i < 13; i++) {

                yearsum = yearsum - 1;
                Log.d("i", "i" + i + yearsum);
            }
            finaldate = yearsum;

My DatePicker dialog

Calendar calender = Calendar.getInstance();
                int year = calender.get(Calendar.YEAR);
                int month = calender.get(Calendar.MONTH);
                int day = calender.get(Calendar.DAY_OF_MONTH);

                Date newDate = new Date(Long.parseLong(getString(finaldate)));

                DatePickerDialog dialog = new DatePickerDialog(Signup.this,
                        new DateListener(), year, month, day);


                             // To set the maximum year

                dialog.getDatePicker().setMaxDate(finaldate);

                dialog.show();

Now i need to show the date upto the date which is 13 years before the current date,

i have used dialog.getDatePicker().setMaxDate(finaldate); line to filter the dates but no luck.`have tried with google but dint get the proper solution. help me to get the solution.

Thanks

도움이 되었습니까?

해결책

To calculate a date 13 years ago from today:

Calendar then = Calendar.getInstance();
then.add(Calendar.YEAR, -13);

To apply it as the max date in date picker:

...getDatePicker().setMaxDate(then.getTimeInMillis());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top