aenugula karthik aenugula karthik - 5 days ago 6
Android Question

I cant be able to set datepicker starts from tomorrows date(Material Design Datepicker)


Iam using Material Design Datepicker i can be able to set from tomorrows date but todays date is also showing in calendar i set for 29/11/2016 but it also showing 28/11/2016
How to disable that so that user cant select it
Iam using Material Design DatePicker
https://github.com/wdullaer/MaterialDateTimePicker


GregorianCalendar g1=new GregorianCalendar();
g1.add(Calendar.DATE, 1);
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DAY_OF_MONTH, 30);
dateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatePickerDialog datePickerDialog ;
datePickerDialog = DatePickerDialog.newInstance(LoginSuccess.this, g1.get(Calendar.YEAR),
g1.get(Calendar.MONTH),
g1.get(Calendar.DAY_OF_MONTH));

datePickerDialog.setTitle("Select Date");
//datePickerDialog.setMinDate(g);
GregorianCalendar c2=new GregorianCalendar();
c2.setTimeInMillis(g1.getTimeInMillis()+(27*7*24*60*60*1000));
//c2.add(Calendar.DAY_OF_MONTH, 30);
List<Calendar> dayslist= new LinkedList<Calendar>();
Calendar[] daysArray;
Calendar cAux = Calendar.getInstance();
while ( cAux.getTimeInMillis() <= gc.getTimeInMillis())
{
if (cAux.get(Calendar.DAY_OF_WEEK)!=1)
{
Calendar c = Calendar.getInstance();
c.setTimeInMillis(cAux.getTimeInMillis());
dayslist.add(c);
}
cAux.setTimeInMillis(cAux.getTimeInMillis()+(24*60*60*1000));
}
daysArray = new Calendar[dayslist.size()];
for (int i = 0; i<daysArray.length;i++)
{
daysArray[i]=dayslist.get(i);
}
//g1.setTimeInMillis(g.getTimeInMillis()+(7*24*60*60*1000));
datePickerDialog.setMinDate(g1);
datePickerDialog.setMaxDate(c2);
datePickerDialog.show(getFragmentManager(), "DatePickerDialog");
datePickerDialog.setSelectableDays(daysArray);

}

Answer

Try this out!

dateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar now = Calendar.getInstance();
            now.add(Calendar.DAY_OF_YEAR, 1);
            DatePickerDialog dpd = DatePickerDialog.newInstance(
                    MainActivity.this,
                    now.get(Calendar.YEAR),
                    now.get(Calendar.MONTH),
                    now.get(Calendar.DAY_OF_MONTH)
            );
            dpd.setMinDate(now);
            dpd.setThemeDark(modeDarkDate.isChecked());
            dpd.vibrate(vibrateDate.isChecked());
            dpd.dismissOnPause(dismissDate.isChecked());
            dpd.showYearPickerFirst(showYearFirst.isChecked());
            if (modeCustomAccentDate.isChecked()) {
                dpd.setAccentColor(Color.parseColor("#9C27B0"));
            }
            if(titleDate.isChecked()) {
                dpd.setTitle("DatePicker Title");
            }
            dpd.show(getFragmentManager(), "Datepickerdialog");
        }
    });
}
Comments