0

i'm developing android app which requires calender with Only 7 days from current date : if Today is Wed day, so results will be wed -- till tuesday i need to show in view of my calender.

Calendar instance = Calendar.getInstance();
widget.setSelectedDate(instance.getTime());
Calendar instance1 = Calendar.getInstance();
instance1.set(instance1.get(Calendar.YEAR), Calendar.JANUARY, 1);
Calendar instance2 = Calendar.getInstance();
instance2.set(instance2.get(Calendar.YEAR), Calendar.DECEMBER, 31);
widget.state().edit()
        .setMinimumDate(instance1.getTime())
        .setMaximumDate(instance2.getTime())
        .commit();
widget.addDecorators(
        new MySelectorDecorator(this),
        new HighlightWeekendsDecorator(),
        oneDayDecorator);
Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50

2 Answers2

2

If you use CalendarView or DatePickerDialog, you can set min date = today and set max date = today + 7.

CalendarView calendarView = (CalendarView) findViewById(R.id.cl);
long currentTime = System.currentTimeMillis();
long maxTime = currentTime + 1000 * 60 * 60 * 24 * 7;
calendarView.setMinDate(currentTime);
calendarView.setMaxDate(maxTime);

Hope it can help you.

CoXier
  • 2,523
  • 8
  • 33
  • 60
0

You leave your code exactly how it is and just remove your set call. When you call getInstance for a calendar you will get back a calendar instance that is set to the current date and time.

Ex:

SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Calendar date = Calendar.getInstance();

for(int i = 0; i < 7;i++){
    Calendar[i] = format.format(date.getTime());
    date.add(Calendar.DATE  , 1);
    System.out.println("date :" + Calendar[i]);
}
Dilip
  • 2,622
  • 1
  • 20
  • 27