简体   繁体   中英

Android Studio - Date picker current date not accessing previous calendar dates?

I am using date picker in android studio which on default shows year 1990 so i set the date picker to the current time.On doing this the previous day, month and year disappears. What i want is to set the date picker to current date but still has access to previous calendar.

 java.util.Date currentTime = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(currentTime.getTime());

        int Day = calendar.get(Calendar.DAY_OF_MONTH);
         int  Month = calendar.get(Calendar.MONTH);
        int Year = calendar.get(Calendar.YEAR);



Edit_SelectDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            dpd = new DatePickerDialog(PURCHASE.this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int mDay, int mMonth, int mYear) {
                    calendar.set(Calendar.YEAR, mYear);
                    calendar.set(Calendar.MONTH, mMonth);
                    calendar.set(Calendar.DAY_OF_MONTH, mDay);

                   // Edit_SelectDate.setText(mDay + "/" + (mMonth + 1) + "/" + mYear);
                    Edit_SelectDate.setText(mYear + "/" + (mMonth + 1) + "/" + mDay);
                }
            }, Day, Month, Year);
            dpd.getDatePicker().setMinDate(System.currentTimeMillis());

            dpd.show();



        }
    });

i guess its about dpd.getDatePicker().setMinDate(System.currentTimeMillis()); you set minimum date to now ( System.currentTimeMillis() ), so you cant see past.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM