Skip to content

The Switch Form Cell

The switch form cell represents a key value cell in which the value is a Boolean object that is controlled by a switch. This cell also supports facilities to set helper or error texts.

Using the Switch Form Cell

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

        <com.sap.cloud.mobile.fiori.formcell.SwitchFormCell
            android:id="@+id/testSwitch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:helperEnabled="true"
            app:helperText="This is helper message"
            app:key="Switch Key"
            app:value="true" />

Editable and Non-Editable Modes

For the switch form cell, editable and enabled attributes are the same: a non-editable cell is not enabled (not clickable, not focusable and 50% alpha). By default, the switch form cell is editable and enabled. You can control the editability of the cell by using XML attribute app:editable="false", You can also fetch the view in your activity and set it to be editable:

       SwitchFormCell mSwitchFormCell = findViewById(R.id.testSwitch);
       mSwitchFormCell.setIsEditable(false);

For more information about the editable attribute, see FormCell.

Error and Helper Texts

To set the error and helper text on the view, enable the feature on the view by calling setErrorEnabled and setHelperEnabled respectively. You can also use app:errorEnabled and app:helperEnabled XML attributes to enable the support for these features. Once enabled, you can call setError(CharSequence) to set the error text and setHelperText to set the helper text. Once set, the error/helper text remains enabled, until setErrorEnabled(false)/setHelperEnabled(false) is called.

Error and Helper Texts

Listening for Cell Value Changes

To listen for updates to a cell value, attach a CellValueChangeListener\ using setCellValueChangeListener:

mSwitchFormCell.setCellValueChangeListener(new FormCell.CellValueChangeListener<Boolean>() {
            @Override
            protected void cellChangeHandler(@NonNull Boolean value) {
                // App level logic
            }
        });

Also see FormCell


Last update: April 14, 2021