Skip to content

CustomListDialog

Philipp Niedermayer edited this page Feb 2, 2017 · 10 revisions

CustomListDialog

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 positions)
    .choicePreset(List<Integer> positions)
    .choicePreset(int[] positions)
    Defines the initially checked item position 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
  • 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)

Clone this wiki locally