Skip to content

The Simple Property Form Cell

The simple property form cell represents a key value cell in which the value is a single line editable text field. This cell also supports facilities to set helper or error texts.

Using the Simple Property Form Cell

The simple property form cell can be used within your activity like any traditional Android view:

1
2
3
4
5
6
<com.sap.cloud.mobile.fiori.formcell.SimplePropertyFormCell
        android:id="@+id/SimplePropertyFormCell1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:key="Cell key"
        app:value="Cell value" />

Editable and Non-Editable Modes

Like other form cells, this form cell can also be set to editable or non-editable modes. A non-editable cell is enabled but the value field on the cell is not editable.

By default, the simply property form cell is editable. 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:

1
2
       SimplePropertyFormCell mSimplePropertyCell = findViewById(R.id.simpleproperty_formcell);
       mSimplePropertyCell.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.

Text Selectable

The simple property form cell also allows you to enable or disable the ability to select the value text in non-editable states. You can check different variants in action at NoteFormCell Demo.

Listening for Cell Value Changes

To listen for updates to the cell value, attach a CellValueChangeListener\<CharSequence> using setCellValueChangeListener:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mSimplePropertyFormCell.setCellValueChangeListener(new FormCell.CellValueChangeListener<CharSequence>() {
            @Override
            protected void cellChangeHandler(@NonNull CharSequence value) {
                if (value.length() > 20) {
                    mSimplePropertyFormCell1.setErrorEnabled(true);
                    mSimplePropertyFormCell1.setError("This is too long value");
                } else {
                    mSimplePropertyFormCell1.setErrorEnabled(false);
                }
            }
        });

Alternate Input Methods

The default method for users to input values into the simple property form cell is with a keyboard. An alternative is to scan barcodes and have that value entered into the simple property form cell.

To use an alternate input method, add a secondaryActionType attribute to your SimplePropertyFormCell layout. You can also call setSecondaryActionType on the simple property form cell. The supported values for secondaryActionType are BARCODE and NONE.

Barcode Scan Input

To add barcode scanning support, add a secondaryActionType attribute to your layout with the value set to BARCODE:

1
2
3
4
5
6
7
<com.sap.cloud.mobile.fiori.formcell.SimplePropertyFormCell
        android:id="@+id/SimplePropertyFormCell1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:secondaryActionType="BARCODE"
        app:key="Cell key"
        app:value="Cell value" />

Or, call setSecondaryActionType on your simple property form cell:

1
mSimplePropertyFormCell.setSecondaryActionType(BARCODE);

Either approach adds a barcode scan button to the end of the simple property form cell. By default, when the user taps the scan button, a scanning activity is launched to scan a barcode. You will need to implement your own validator, similar to the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class SampleBarcodeValidator implements QRCodeReaderActionHandler {
    private static Barcode mBarcode;

    @Override
    public void validateBarcode(Fragment fragment, Barcode barcode)
        throws BarcodeValidationException, InterruptedException {

        ((DemoApplication) fragment.getActivity().getApplication()).delay();
        if (barcode == null) {
            throw new BarcodeValidationException("Null barcode");
        } else {
            mBarcode = barcode;
        }
    }

    public static Barcode getBarcode() {
        return mBarcode;
    }
}

In your activity, add an onActivityResult method to collect the scanned value:

1
2
3
4
5
6
7
8
9
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQ_CAMERA &&
            resultCode == Activity.RESULT_OK &&
            SampleBarcodeValidator.getBarcode() != null) {
            // Set value from barcode scan.
            mSimplePropertyFormCell.setValue(SampleBarcodeValidator.getBarcode().displayValue);
        }
    }

If you want to add your own custom behavior when the scan button is tapped, override the tap callback with a setSecondaryActionOnClickListener:

1
2
3
4
5
6
7
mSimplePropertyFormCell.setSecondaryActionOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(mSimplePropertyFormCell.getContext(),
            "Custom secondary action", Toast.LENGTH_SHORT).show();
    }
});

See also FormCell