Skip to content

Commit

Permalink
Add an example showing how to change the default selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wdullaer committed Oct 27, 2019
1 parent e719d6e commit de5ee5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.wdullaer.materialdatetimepicker.date;

public enum DayOfWeek {
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DatePickerFragment extends Fragment implements DatePickerDialog.OnD
private CheckBox switchOrientation;
private CheckBox limitSelectableDays;
private CheckBox highlightDays;
private CheckBox defaultSelection;
private DatePickerDialog dpd;

public DatePickerFragment() {
Expand All @@ -57,6 +58,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
switchOrientation = view.findViewById(R.id.switch_orientation);
limitSelectableDays = view.findViewById(R.id.limit_dates);
highlightDays = view.findViewById(R.id.highlight_dates);
defaultSelection = view.findViewById(R.id.default_selection);

view.findViewById(R.id.original_button).setOnClickListener(v -> {
Calendar now = Calendar.getInstance();
Expand All @@ -72,6 +74,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
// Show a datepicker when the dateButton is clicked
dateButton.setOnClickListener(v -> {
Calendar now = Calendar.getInstance();
if (defaultSelection.isChecked()) {
now.add(Calendar.DATE, 7);
}
/*
It is recommended to always create a new instance whenever you need to show a Dialog.
The sample app is reusing them because it is useful when looking for regressions
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/res/layout/datepicker_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,12 @@
android:text="@string/highlight_dates"
android:checked="false"/>

<CheckBox
android:id="@+id/default_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/default_selection"
android:checked="false"/>

</LinearLayout>
</androidx.core.widget.NestedScrollView>
4 changes: 1 addition & 3 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
<string name="disable_times">Disable specific times</string>
<string name="highlight_dates">Highlight certain dates</string>
<string name="switch_orientation">Switch scroll orientation</string>
<string name="default_selection">Use alternative default selection</string>
<string name="action_settings">Settings</string>

<string name="tab_title_time">Time</string>
<string name="tab_title_date">Date</string>
<string name="tab_title_datetime">Date+Time</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>

</resources>

0 comments on commit de5ee5c

Please sign in to comment.