Skip to content

SimpleFormDialog

Philipp Niedermayer edited this page Feb 23, 2017 · 18 revisions

SimpleFormDialog

extends CustomViewDialog

A Dialog that can be used to create simple or more complex forms.

One can either use one of the following predefined dialogs or use an arbitrary combination of fields as shown below.

  • Login dialog (username or email)
  • Email input
  • Password input
  • Number input

Building dialogs

Examples

SimpleFormDialog.buildLogin(USERNAME, PASSWORD)
                .show(this, LOGIN_DIALOG);
SimpleFormDialog.build()
                .title(R.string.register)
                .msg(R.string.please_fill_in_form)
                .fields(
                        Input.name(NAME).required().hint(R.string.name),
                        Input.password(PASSWORD).required().max(20).validatePatternStrongPassword(),
                        Input.email(EMAIL).required(),
                        Input.plain(COUNTRY).hint(R.string.country)
                             .inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
                             .suggest(R.array.countries_locale).forceSuggestion(),
                        Check.box(null).label(R.string.terms_accept).required()
                )
                .show(this, REGISTRATION_DIALOG);

FormElements

FormElements can be added using the .fields(FormElement...) method as shown above.

Each FormElement gets assigned a custom key-string when created. You can receive the entered value in onResult using this key (see below).
You can also mark every form element as required, so that the user cannot continue, until text was entered, the checkbox checked or a value from the spinner chosen.

The following predefined FormElements exists, but new ones can easily be created by extending the FormElement and FormElementViewHolder classes:

  • Input fields Input
    Options: Hint, initial text, min/max length, suggestions, password visibility toggle button, regular expression based pattern validation
    Required flag: requires this field to contain non white-space text
  • Checkboxes Check
    Options: Label, initial state
    Required flag: requires this field to be checked
  • Spinners Spinner
    Options: Items, label, place-holder text if nothing is selected, initially selected item
    Required flag: requires a value to be chosen. This will remove the place-holder text from the list of choice

Receiving results

In onResults get the entered values from the Bundle like this:

String text = extras.getString(INPUT_KEY);
boolean checked = extras.getBoolean(CHECKBOX_KEY);
int selected = extras.getInt(SPINNER_KEY);

See SimpleDialog

Clone this wiki locally