Date Time Picker Form Cell¶
The date/time picker form cell represents a key value cell, where the value is a date and/or time. Like other form cells, this form cell also supports facilities to set helper or error texts.
Using the DateTimePickerFormCell
¶
This form cell can be used within your activity like any traditional Android view.
<com.sap.cloud.mobile.fiori.formcell.DateTimePickerFormCell
android:id="@+id/dateCell"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
It is important to note that in order to utilize MaterialTimePicker
and
MaterialDatePicker
, you need to pass in a FragmentManager
:
DateTimePickerFormCell mDateTimePickerFormCell = findViewById(R.id.dateCell);
FragmentManager manager = getSupportFragmentManager();
mDateTimePickerFormCell.setManager(manager);
Editable and Non-Editable Modes¶
This form cell can be set to editable or non-editable modes. For this cell, editable and enabled attributes are same: a non-editable form cell is not enabled (not clickable, not focusable
). By default, the form cell is editable and enabled. You can control the editability of the cell using XML attribute app:editable="false
. You can also fetch the view in your activity and set it to be editable:
mDateTimePickerFormCell.setIsEditable(false);
For more information about the editable attribute, see FormCell
.
Date/Time Picker Modes¶
The form cell can be used in four different modes: date and time, date range, date only, or time only.
Date-Time¶
This is the default mode of the cell and allows the user to pick a date and time. You can use the app:dateTimePickerMode="date_time"
XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode)
method to set the cell in date-time mode.
Date Range¶
This mode allows the user to pick a start date and end date and does not show the dialog to pick a time. You can use the app:dateTimePickerMode="range"
XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode)
method to set the cell in date range mode.
Date Only¶
This mode allows the user to pick only a date and does not show the dialog to pick a time. You can use the app:dateTimePickerMode="date"
XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode)
method to set the cell in date mode.
Time Only¶
This mode allows the user to pick only a time and does not show the dialog to pick a date. You can use the app:dateTimePickerMode="time"
XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode)
method to set the cell in time mode.
Text Input Mode¶
To determine whether the date picker or time picker opens in text input mode, use setUseTextDate(boolean)
or setUseTextTime(boolean)
.
DateFormatter
¶
You may want to change the format of the date and time displayed to a user based on locale or some other logic. To change the format, set the Duration Formatter using setDateTimeFormatter(DateFormat)
API on the cell. As shown below,DateTimePickerFormCell
values presented to user in the cell will be first formatted using yourCellValueChangeListener
formatter.
Error and Helper Text¶
Follow design guidelines and see: FormCell
Listening for Cell Value Changes¶
To listen for updates of the cell value, attach a CellValueChangeListener
using setCellValueChangeListener
:
mDateTimePickerFormCell.setCellValueChangeListener(new FormCell.CellValueChangeListener<Date>() {
@Override
protected void cellChangeHandler(@NonNull Date value) {
// Application logic here
}
});
Also see FormCell