Disable date in calendarView - android

1

I would like you to help me disable the dates after today in a calendar view. How could I do it?

This is what I have:

calendario=(CalendarView)findViewById(R.id.cvCalendario);
calendario.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
   @Override
   public void onSelectedDayChange(CalendarView view, int year,int month, int dayOfMonth) {

       //fechaSelect = year + "-" + month + "-" + dayOfMonth;
       fechaSelect = dayOfMonth+"/"+(month+1)+"/"+year;
       fechaCorrecta = year+"-"+"0"+(month+1)+"-"+dayOfMonth;
       Toast.makeText(ctx, fechaSelect, Toast.LENGTH_LONG).show();

       Intent intent;
       intent = new Intent(ctx,Municipios.class);
       intent.putExtra("fechaSelect",fechaSelect);
       intent.putExtra("fechaCorrecta",fechaCorrecta);
       startActivity(intent);
   }
});
    
asked by Javichuelaas 24.05.2016 в 11:39
source

2 answers

1

If you review the documentation, this can be done using the Calendar.init() method:

You get the previous year:

Calendar anoAnterior = Calendar.getInstance();
anoAnterior .add(Calendar.YEAR, -1);

defines the range of dates from the previous year to today:

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date diaActual = new Date();
calendar.init(anoAnterior, diaActual)
    .withSelectedDate(diaActual );

With this we disable the dates after today.

    
answered by 24.05.2016 в 18:56
0

The most convenient thing would be to establish a maximum date value that in this case would be the current date and only then you can manage the established date and the previous or future dates will not be available. Here is the code:

 JDateChooser chooser =  new  JDateChooser (); 
chooser . setMaxSelectableDate ( new  Date ()); 

chooser . setDateFormatString ( "dd-MM-yyyy" ); 

chooser . setDate ( new  Date ());
    
answered by 25.07.2016 в 21:58