Skip to content

SimpleListDialog

Philipp Niedermayer edited this page Sep 27, 2021 · 15 revisions

List single- and multi-choice dialog

extends CustomListDialog, Full API reference

A ListDialog that displays text items. Single choice, direct single choice and multi choice are supported

Building dialogs

Example

CustomListDialog.build()
                .title(R.string.select_one)
                .items(context, new int[]{R.string.choiceA, R.string.choiceB, R.string.choiceC})
                .choiceMode(SINGLE_CHOICE)
                .show(Activity.this, DIALOG_1);

Customizations

All of CustomListDialog plus:

  • Labels
    .items(String[] labels)
    .items(Context context, @ArrayRes int labelArrayResourceIds)
    .items(Context context, int[] labelsResourceIds)
    .items(String[] labels, long[] ids)
    Populate the list with the labels provided (either Strings or android resource ids). Optionally, an array of ids can be used to identify which labels were selected in onResult.
  • Items
    items(ArrayList<? extends SimpleListItem> items)
    Use a custom set of objects extending SimpleListItem and overwrite it's getString() and (optionally) getId() method.
  • Layout layout(int layout)
    Customize the item layout (one of the many presets available or a custom layout resource)

Receiving results

See Receiving results from SimpleDialog. The extras Bundle returned will contain the keys for each field as specified when the dialog was created. i.e.:

// Selected IDs or labels (except in `NO_CHOICE`-mode)
ArrayList<String> labels = extras.getStringArrayList(SimpleListDialog.SELECTED_LABELS);
long[] ids = extras.getLongArray(SimpleListDialog.SELECTED_IDS); // derived from CustomListDialog

// Selected ID or label (only for `SINGLE_CHOICE`- and `SINGLE_CHOICE_DIRECT`-mode)
String label = extras.getString(SimpleListDialog.SELECTED_SINGLE_LABEL);
long id = extras.getLong(SimpleListDialog.SELECTED_SINGLE_ID);  // derived from CustomListDialog

Clone this wiki locally