Skip to content

The Generic List Picker Form Cell

GenericListPickerFormCell is an enhanced version of the older ListPickerFormCell class.

Applications often present a long list of items and allow users to express their choice in either single or multiple selections.

GenericListPickerFormCell is designed to handle such complex lists with ease and allow developers to:

  • Inflate custom views to present the target items.
  • Bind items by their position or custom id.
  • Track user interactions and selections, and notify the application of the changes through callbacks.

The cell can easily be configured to allow:

  • Single selection only – Presents the list of items with radio buttons and allows only one selection.
  • Multi selection – Presents the list of items with check boxes and allows users to make multiple selections.

This Cell also allows you to perform paging for better performance. For example, if you have 100,000 elements to present, then GenericListPickerFormCell allows you to only fetch the initial 100 elements and then load new elements as the user scrolls the list.

Using the GenericListPickerFormCell

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

                    app:activityTitle="Choose Text"
                    app:key="Pick Text Options" />

GenericListPickerFormCell Activity

The GenericListPickerFormCell depends on GenericListPickerFormCellActivity to present the list items. GenericListPickerFormCellActivity 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.

As shown in the following example, GenericListPickerFormCellActivity has two generic parameters:

  • V extends View – Represents the type of views to be presented to user; for example, TextView or ObjectCell

  • T extends Serializable – Represents the type of key used to identify two different elements in the list being presented; for example, position of the item in actual list or item id from your database

class GenericListPickerFormCellActivity<V extends View, T extends Serializable> extends ...

In order to create and bind the data, GenericListPickerFormCellActivity follows the RecyclerView.Adapter pattern. For the ease of usage, APIs of the Activity are named along the lines of RecyclerView.Adapter APIs.

The following table lists the methods, with descriptions, that you have to override to set up the GenericListPickerFormCellActivity.

Abstract Methods Description
int getItemCount() Informs the GenericListPickerFormCellActivity about the number of items in the List.
int getItemViewType(int position) Inflates different types of list item views. This method informs the GenericListPickerFormCellActivity about type of the view at a given position.
V onCreateView(int viewType, @NonNull Context context) Given a view type, creates 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.
T getId(int pos) Given a position in adapter, return the id used for the item.
  • You can use app:value XML attribute or setValue(List<Integer>) to set the already selected value on the cell.

  • You can set GenericListPickerFormCellActivity using setPickerActivity(@Nullable GenericListPickerFormCellActivity<V, ?> pickerActivity) method on the form cell.


You can replace the GenericListPickerFormCellActivity with GenericListPickerFormCellFragment for presenting the items in list. Unlike GenericListPickerFormCellActivity, GenericListPickerFormCellFragment itself is not responsible for creating the list items but depends on GenericListPickerFormCellAdapter class for the same. Like GenericListPickerFormCellActivity, GenericListPickerFormCellAdapter also has similar abstract methods and two generic parameters:

  • V extends View – Represents the type of views to be presented to user; for example, TextView or ObjectCell.
  • T extends Serializable – Represents the type of key used to identify two different elements in the list being presented; for example, position of the item in actual list or item id from your database.


While using GenericListPickerFormCellFragment, SDK has no ways to know when and how to add the fragment. Hence app should add the fragment whenever required, preferably onClick events on GenericListPickerFormCell.

Generic Picker Object 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.

Show selected Section Do not show selected section
With Selection No Selection

Single select mode of the GenericListPickerFormCell does not support the selected section.

Left To Right

GenericListPickerFormCell allows you to position the selector (checkbox or radio) button on either left of right end of the item view. Using setLeftToRight API on GenericListPickerFormCell, you can position the selector on either end.

By default, selectors are positioned on the start or left end of the item.

Selector on Left Selector on Right
Selector on Left Selector on Right

Paging Using GenericListPickerFormCell

If it is desired to present a long list of items to the user, then it is good practice to load the items when required. Loading only partial lists saves memory and computation resources.

You can override the void onBindPosition(int pos) method in GenericListPickerFormCellActivity class to be notified when the adapter position of the item for which onBindView(@NonNull V view, T id) is called. This gives you an indication as to whether your current list is going to be exhausted and you can trigger network calls to download more items.

protected void onBindPosition(int pos) {
        if(pos < getItemCount() - 10) {
            // trigger the network call to load more items as we have only 10 more spare items to present

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.

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 using Java APIs.

       GenericListPickerFormCell mPickerFormCell = findViewById(;

For more information about the editable attribute, see FormCell.

Error and Helper

Follow design guidelines and see FormCell

Listening for Cell Value Changes

Like all FormCells, GenericListPickerFormCell notifies the application about changes through CellValueChangeListener. To listen for updates to a cell value, attach a CellValueChangeListener using setCellValueChangeListener:

mPickerFormCell.setCellValueChangeListener(new FormCell.CellValueChangeListener<List<T>>() {
            protected void cellChangeHandler(@NonNull List<T> value) {
                // Application logic here

See also FormCell.

Last update: November 18, 2021