Skip to content

Commit de5ee5c

Browse files
committed
Add an example showing how to change the default selection
1 parent e719d6e commit de5ee5c

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.wdullaer.materialdatetimepicker.date;
2+
3+
public enum DayOfWeek {
4+
}

sample/src/main/java/com/wdullaer/datetimepickerexample/DatePickerFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DatePickerFragment extends Fragment implements DatePickerDialog.OnD
3232
private CheckBox switchOrientation;
3333
private CheckBox limitSelectableDays;
3434
private CheckBox highlightDays;
35+
private CheckBox defaultSelection;
3536
private DatePickerDialog dpd;
3637

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

6163
view.findViewById(R.id.original_button).setOnClickListener(v -> {
6264
Calendar now = Calendar.getInstance();
@@ -72,6 +74,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
7274
// Show a datepicker when the dateButton is clicked
7375
dateButton.setOnClickListener(v -> {
7476
Calendar now = Calendar.getInstance();
77+
if (defaultSelection.isChecked()) {
78+
now.add(Calendar.DATE, 7);
79+
}
7580
/*
7681
It is recommended to always create a new instance whenever you need to show a Dialog.
7782
The sample app is reusing them because it is useful when looking for regressions

sample/src/main/res/layout/datepicker_layout.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,12 @@
9292
android:text="@string/highlight_dates"
9393
android:checked="false"/>
9494

95+
<CheckBox
96+
android:id="@+id/default_selection"
97+
android:layout_width="wrap_content"
98+
android:layout_height="wrap_content"
99+
android:text="@string/default_selection"
100+
android:checked="false"/>
101+
95102
</LinearLayout>
96103
</androidx.core.widget.NestedScrollView>

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
<string name="disable_times">Disable specific times</string>
2727
<string name="highlight_dates">Highlight certain dates</string>
2828
<string name="switch_orientation">Switch scroll orientation</string>
29+
<string name="default_selection">Use alternative default selection</string>
2930
<string name="action_settings">Settings</string>
3031

3132
<string name="tab_title_time">Time</string>
3233
<string name="tab_title_date">Date</string>
3334
<string name="tab_title_datetime">Date+Time</string>
3435

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

0 commit comments

Comments
 (0)