我想实现一个材质设计DatePicker,用户可以在其中选择日期范围。所以我在github上找到了这个精彩的库,它完全符合我的要求: https://github.com/vikramkakkar/SublimePicker
但绝对没有关于如何使用它的文档。经过几个小时的研究,我想出了如何显示日历。以下是我的代码。问题是,我不知道如何setPositiveButton
或setNegativeButton
。没有它,我无法保存日期/日期范围。
SublimePickerFragment.Callback mFragmentCallback = null;
SublimePickerFragment pickerFrag = new SublimePickerFragment();
pickerFrag.setCallback(mFragmentCallback);
SublimeOptions sublimeOptions = new SublimeOptions();
sublimeOptions.setDisplayOptions(SublimeOptions.ACTIVATE_DATE_PICKER);
sublimeOptions.setPickerToShow(SublimeOptions.Picker.DATE_PICKER);
sublimeOptions.setDateParams(Calendar.getInstance());
sublimeOptions.setCanPickDateRange(true);
sublimeOptions.setAnimateLayoutChanges(true);
Bundle bundle = new Bundle();
bundle.putParcelable("SUBLIME_OPTIONS", sublimeOptions);
pickerFrag.setArguments(bundle);
pickerFrag.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
pickerFrag.show(this.getFragmentManager(), "SUBLIME_PICKER");
有什么建议吗?谢谢!
答案 0 :(得分:1)
我终于找到了解决方案。我必须设置一个回调函数,当单击OK或CANCEL时将调用该函数。下面是代码。希望这有助于某人!
SublimePickerFragment.Callback mFragmentCallback = new SublimePickerFragment.Callback() {
@Override
public void onCancelled() {
// when CANCEL is clicked
}
@Override
public void onDateTimeRecurrenceSet(SelectedDate selectedDate, int hourOfDay, int minute, SublimeRecurrencePicker.RecurrenceOption recurrenceOption, String recurrenceRule) {
// when OK is clicked
System.out.println(selectedDate.toString());
}
};