Skip to content

The List Picker Form Cell

Important

ListPickerFormCell has been deprecated and replaced with the generic GenericListPickerFormCell class. See GenericListPickerFormCell Class for information.

Overview

Applications are often required to present a long list of options so that a user may pick a single option or multiple options. The list picker form cell enables you to present such complex lists with the ability to inflate custom views to present the target items.

The cell also enables you to limit the selection to single select only or to allow multiple selections.

In the case of single select, a long list of options are presented in an activity containing list with radio buttons. In the case of multi-select, the list is presented with check boxes.

Using the List Picker Form Cell

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

1
2
3
4
5
6
7
        <com.sap.cloud.mobile.fiori.formcell.ListPickerFormCell
            android:id="@+id/listPickerCell"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:activityTitle="Choose ObjectCell"
            app:key="Pick ObjectCell Options"
            app:value="@array/selected_values" />

Setting up the List Items

The list picker form cell depends on ListFormCellFilterActivity to present the list items. ListFormCellFilterActivity is an abstract class responsible for creating the list items, presenting them to a user, tracking the user actions, and informing the form cell about the changes made. This form cell notifies the application about the changes through CellValueChangeListener.

You can set ListFormCellFilterActivity using setListFormCellFilterActivity(@Nullable ListFormCellFilterActivity listFormCellFilterActivity) method on the form cell.

ListFormCellFilterActivity follows the RecyclerView.Adapter pattern to inflate and present the list of items. Below is a list of methods with description that you have to override in ListFormCellFilterActivity in order to set up the ListPickerFormCell.

Abstract Methods Description
int getItemCount() Informs the ListFormCellFilterActivity about the number of items in the List.
int getItemViewType(int position) Inflates different types of list item views. This method informs the ListFormCellFilterActivity about type of the view at given position.
V onCreateView(int viewType, @NonNull Context context) Given a view type create the View
void onBindView(@NonNull V view, int position) This is where you bind your view with data. Given position and view bind it to data.

You can use "app:value" XML attribute or setValue(List) to set the already selected value on the cell.

Selection Section

The list picker form cell comes with a selection section which, when it is enabled, shows all the selected items on top of the list. You can enable or disable the selection section with setShowSelected(boolean) method.

Editable and Non-Editable Modes

This form cell can be set to editable or non-editable modes. For the list picker form cell,editable and enabled attributes are the same: a non-editable form cell is not enabled (not clickable, not focusable). By default, the list picker 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:

1
2
       ListPickerFormCell mListPickerFormCell = findViewById(R.id.listPickerCell);
       mListPickerFormCell.setIsEditable(false);
For more information about the editable attribute, see FormCell.

Error and Helper

Follow design guidelines and see FormCell

Listening for Cell Value Changes

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

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