Search code examples
androidandroid-preferences

ListPreference with a max number of selectable options


I want to have an element in my preference menu that does the following:

  • Show a list of options.
  • Many are selectable
  • Maximum amount of options to be chosen 2.

Possibilities I thought of:

  1. Doing a separated PreferenceScreen and showing options as checkBoxes, but I don't know where to place the logic of max 2 options.
  2. Extending DialogPreference and doing it by hand.

What's the best way?


Solution

  • Extending DialogPreference would get you the closest in terms of look-and-feel; the Preference classes are fairly unflexible and un-extendable in my experience.

    I can't remember too much about PreferenceScreen, but I imagine it's similar.

    In an app I worked on, we ended up using separate activities, launched via Intent from a Preference item onClick. This allowed us to easily develop preference screens that require validation logic a bit more complex than the usual.