0
私はBetterpickersをカレンダーの日付ピッカーに使用しています。私は特定の日付を無効にする必要があります(APIから来ています)。私はいくつかの日付を無効にしようとしましたが、私のコードはその日付を無効にしませんでした。無効な唯一の日付は、設定された日付範囲外の日付、つまり、minDateおよびmaxDateです。これらは私のコードに問題がありますか?無効な特定の日付範囲
public class MainActivity extends AppCompatActivity implements CalendarDatePickerDialogFragment.OnDateSetListener{
Button dateBtn;
private static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dateBtn = (Button)findViewById(R.id.dateBtn);
dateBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// For Calendar range
DateTime now = DateTime.now();
MonthAdapter.CalendarDay minDate = new MonthAdapter.CalendarDay(now.getYear(), now.getMonthOfYear()-1, now.getDayOfMonth());
MonthAdapter.CalendarDay maxDate = new MonthAdapter.CalendarDay(now.getYear()+1, now.getMonthOfYear(), now.getDayOfMonth());
Calendar startCal = Calendar.getInstance();
startCal.setTimeInMillis(minDate.getDateInMillis());
Calendar endCal = Calendar.getInstance();
endCal.setTimeInMillis(maxDate.getDateInMillis());
SparseArray<MonthAdapter.CalendarDay> disabledDays = new SparseArray<>();
// For diable date range
String startdateTime = "2017/03/12";
String enddateTime = "2017/03/30";
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/MM/dd");
DateTime startJodaDate = dtf.parseDateTime(startdateTime);
DateTime endJodaDate = dtf.parseDateTime(enddateTime);
MonthAdapter.CalendarDay minDisableDate = new MonthAdapter.CalendarDay(startJodaDate.getYear(), startJodaDate.getMonthOfYear(), startJodaDate.getDayOfMonth());
MonthAdapter.CalendarDay maxDisableDate = new MonthAdapter.CalendarDay(endJodaDate.getYear(), endJodaDate.getMonthOfYear(), endJodaDate.getDayOfMonth());
Calendar startDisableCal = Calendar.getInstance();
startDisableCal.setTimeInMillis(minDisableDate.getDateInMillis());
Calendar endDisableCal = Calendar.getInstance();
startDisableCal.setTimeInMillis(maxDisableDate.getDateInMillis());
while (startDisableCal.before(endDisableCal)) {
int key = Utils.formatDisabledDayForKey(startDisableCal.get(Calendar.YEAR),
startDisableCal.get(Calendar.MONTH), startDisableCal.get(Calendar.DAY_OF_MONTH));
disabledDays.put(key, new MonthAdapter.CalendarDay(startDisableCal));
startDisableCal.add(Calendar.DATE, 1);
}
CalendarDatePickerDialogFragment cdp = new CalendarDatePickerDialogFragment()
.setDateRange(minDate, maxDate)
// Set Disabled Days
.setDisabledDays(disabledDays)
.setOnDateSetListener(MainActivity.this);
cdp.show(getSupportFragmentManager(), FRAG_TAG_DATE_PICKER);
}
});
}
@Override
public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
int correctMonth = monthOfYear+1;
System.out.println("sammy_DATE: "+dayOfMonth+"/"+correctMonth+"/"+year);
}
}
少なくとも、あなたは、クエリに答えるされていない場合でも、ダウン票に理由を与えます。 –