Search code examples
androidandroid-alertdialogandroid-dialogfragmentandroid-dialogdialogfragment

Building DialogFragment with partially static and dynamic layout


I want to build a DialogFragment that looks like this:

  1. it has a spinner/drop-down menu in the top part of the content area that allows user to select a state
  2. the layout below (1) changes depending on the state
  3. the positive button of the dialog does different things depending on the state and the values the user select using the widgets in (2)
  4. (1) is the fixed part; it is always there.

Should I use a single DialogFragment and swap layouts? Or should I just build multiple DialogFragments?


Solution

  • You should use a single DialogFragment, and for the layout under (1) use a FrameLayout containing the possible states, and change the visibility on change of (1), or a ViewSwitcher depending on your favour.