Skip to content

CustomListDialog

Philipp Niedermayer edited this page Sep 14, 2018 · 10 revisions

Dialogs with custom lists

extends CustomViewDialog

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

Available customizations

  • Choice mode
    .choiceMode(int mode)
    Sets the mode to one of NO_CHOICE, SINGLE_CHOICE, SINGLE_CHOICE_DIRECT or MULTI_CHOICE.
  • 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 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, 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

Custom Adapter

protected abstract ListAdapter onCreateAdapter()

Create and return your custom Adapter here.

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

The Bundle returned from this dialog will contain the following extras depending on the choice

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)