/ / "wdullaer materialdatetimepicker"でカスタムの最小値と最大値の選択日を設定する方法 - android、android-studio、datetimepicker、custom-datetimepicker

"wdullaer materialdatetimepicker"でカスタムの最小値と最大値の選択日を設定する方法 - android、android-studio、datetimepicker、custom-datetimepicker

私は、私が望む以外の日付をユーザーが選択するのを制限する必要があるプロジェクトに取り組んでいます。

いくつかの記事を読んで、私は仕事をしなければならない

    com.wdullaer.materialdatetimepicker.date.DatePickerDialog dpd = newInstance(
ActivityClaimOffers.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setMinDate(calendar);
dpd.setMaxDate(calendar);

しかし、私 カレンダーオブジェクトとしてカスタムの日付を渡す方法を理解できませんでした。 setMinDate()とsetMaxDate()はCalendarをパラメータとして取ります

回答:

回答№1の場合は3

このような :

Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);

あなたのコードのために:

dpd.setMinDate(new GregorianCalendar(2000, 5, 23));

回答№2については2

ちょっとこのコードのように私はこのようにしてみてください

Calendar nowMinimum = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
this,
nowMinimum.get(Calendar.YEAR),
nowMinimum.get(Calendar.MONTH),
nowMinimum.get(Calendar.DAY_OF_MONTH));

dpd.setMinDate(nowMinimum); //today"s date is minimum

Calendar thenMaximum = Calendar.getInstance();
thenMaximum.set(year, monthOfYear, dayOfMonth);// you can pass your custom date

dpd.setMinDate(thenMaximum);
dpd.setTitle("Select Date");
dpd.show(getActivity().getFragmentManager(), "date_picker");