Skip to content

DateTime 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 DateTime Picker Form Cell

This form cell can be used within your activity like any traditional Android view.

1
2
3
4
<com.sap.cloud.mobile.fiori.formcell.DateTimePickerFormCell
        android:id="@+id/dateCell"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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:

1
2
       DateTimePickerFormCell mDateTimePickerFormCell = findViewById(R.id.dateCell);
       mDateTimePickerFormCell.setIsEditable(false);
For more information about the editable attribute, see FormCell.

Date/Time Picker Modes

The form cell can be used in three different modes: date and time, 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 "app:dateTimePickerMode="date_time"" XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode) method to set the cell in Date-Time 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 "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 "app:dateTimePickerMode="time"" XML attribute or setDateTimePickerMode(@NonNull DateTimePicker.DateTimePickerMode) method to set the cell in Time mode.

Date Formatter

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 DateFormatter using setDateTimeFormatter(DateFormat) API on the cell. As shown below, DateTimePickerFormCell values presented to user in the cell will be first formatted using your datetime formatter.

1

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:

1
2
3
4
5
6
mDateTimePickerFormCell.setCellValueChangeListener(new FormCell.CellValueChangeListener<Date>() {
            @Override
            protected void cellChangeHandler(@NonNull Date value) {
                // Application logic here
            }
        });
Also see FormCell