title: How to set the limit on date in Date picker dialog
body: <p>I want to put the limit on date so that user can not pick date more then that, for example if today is 1 January then User should not be able to select more then 7 dates , I mean he can not select 9 January. I also want him not to select the month and year. So I am putting a limit to set his task in one week. </p>
  
  <p>what I have done so far is showing the date picker fragment and setting current date in it. the code in my main activity goes like this:</p>
  
  <pre><code>etSelectDate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  DialogFragment datePickerFragment = new DatePickerFragment() {
                      @Override
                      public void onDateSet(DatePicker view, int year, int month, int day) {
                          Log.d("Date Change", "onDateSet");
                          Calendar c = Calendar.getInstance();
                          c.set(year, month, day);
                          DateFormat df = DateFormat.getDateInstance();
                          etSelectDate.setText(df.format(c.getTime()));
                          //nextField.requestFocus(); //moves the focus to something else after dialog is closed
  
                      }
                  };
                  datePickerFragment.show(MainActivity.this.getSupportFragmentManager(), "datePicker");
  
              }
          });
  </code></pre>
  
  <p>and date picker fragment class goes like this :</p>
  
  <pre><code> public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
  
          @Override
          public Dialog onCreateDialog(Bundle savedInstanceState) {
              // Use the current date as the default date in the picker
              final Calendar c = Calendar.getInstance();
              int year = c.get(Calendar.YEAR);
              int month = c.get(Calendar.MONTH);
              int day = c.get(Calendar.DAY_OF_MONTH);
  
              // Create a new instance of DatePickerDialog and return it
              return new DatePickerDialog(getActivity(), this, year, month, day);
          }
  
          @Override
          public void onDateSet(DatePicker view, int year, int month, int day) {
              //blah
          }
      }
  </code></pre>
  
  <p>till then its is working fine , but I do not know how to put the limit on date and rest of the months and year should be non Select able . I have seen many link such as like <a href="https://stackoverflow.com/questions/18272306/set-limit-on-the-datepickerdialog-in-android">this</a> , but I do not understand How can I do that and also there is nothing helpful on android site. </p>
  
  <blockquote>
    <p>So please help me , How can I put limit of seven days only</p>
  </blockquote>
  
  <p><strong>Update</strong></p>
  
  <p>Through your replies I know how to set the max date in calender , so As I want to set the max date 7 days ahead of current date , I am still not getting it. the method I read so far is :</p>
  
  <pre><code>pickerDialog.getDatePicker().setMaxDate(new Date().getTime());
  </code></pre>
  
  <p>It is setting the current date as maximum, but How can I add 7 days ahead in it since it is Date object ? please help </p>