Skip to content

CustomListDialog

Philipp Niedermayer edited this page Oct 3, 2021 · 10 revisions

Dialogs with custom lists

extends CustomViewDialog, Full API reference

Extend this class to create a dialog with a custom ListView.

Available customizations

  • Choice mode
    .choiceMode(int mode)
    Defines the behaviour when items are selected by setting the mode to one of
    • NO_CHOICE - items can not be selected
    • SINGLE_CHOICE - only one item can be selected at a time
    • SINGLE_CHOICE_DIRECT - selecting an item closes the dialog as if the positive button was pressed
    • MULTI_CHOICE - multiple items can be (un-)selected
  • Choice preset
    .choicePreset(int position)
    .choicePreset(List<Integer> positions)
    .choicePreset(int[] positions)
    .choiceIdPreset(long id)
    .choiceIdPreset(List<Long> ids)
    .choiceIdPreset(long[] ids)
    Defines the initially checked item(s) by position(s) or id(s) in SINGLE_CHOICE and MULTI_CHOICE mode respectively.
  • Control choice count
    .choiceMin(int count)
    .choiceMax(int count)
    Defines minimum required and maximum allowed number of checked items in MULTI_CHOICE-mode
  • Filter
    .filterable(boolean enabled) When enabled, a search box appears at the top, so the user can filter the list by searching for a keyword.
  • Grid layout
    .grid()
    Enables the grid-layout
    .gridNumColumn(int numColumns)
    Defines the number of columns in the grid
    .gridColumnWidth(@DimenRes int columnWidthDimenResId)
    Defines the with of the columns in the grid
  • Show / hide divider
    .divider(boolean show)
    Show or hide divider between list items

Custom Adapter

protected abstract ListAdapter onCreateAdapter()

Overwrite this method to create and return your custom Adapter here. See SimpleListDialog for an example.

Handling clicks

public void onItemClick(AdapterView<?> parent, View view, int position, long id)
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)

Overwrite these methods to react on clicks and long clicks on list items (optional).

Receiving results

See Receiving results from SimpleDialog. The extras Bundle returned will contain the following keys depending on the choice type:

ArrayList<Integer> SELECTED_POSITIONS       // Selected Positions (except in `NO_CHOICE`-mode)
            long[] SELECTED_IDS             // Selected ID's (only present if the Adapter provides stable ids)
               int SELECTED_SINGLE_POSITION // Selected Position (only for `SINGLE_CHOICE`- and `SINGLE_CHOICE_DIRECT`-mode)
              long SELECTED_SINGLE_ID       // Selected ID (only present if the Adapter provides stable ids)

Clone this wiki locally