Skip to content

CustomViewDialog

Philipp Niedermayer edited this page Mar 29, 2018 · 13 revisions

Dialogs with custom views

extends SimpleDialog

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

Requirements

It is strongly recommended to create a TAG field which will be used as a default tag for receiving results:

public static final String TAG = "YourTag";

If you want to use the builder, make sure to overwrite the .build() function:

public static MyDialog build() {
    return new MyDialog();
}

Inflate view

protected abstract View onCreateContentView(Bundle savedInstanceState)

Inflate, setup and return your custom view here.
For inflating, use one of the provided inflate(...) functions to make sure custom theme attributes are applied correctly.

Providing results

protected Bundle onResult(int which)

Overwrite this method to return a Bundle that will be merged into the results returned by OnDialogResultListener.onResult.

Various

protected void onDialogShown()

Overwrite this method to take action once the dialog is shown such as settings the initial state of the positive button (see below) or an input focus.

protected boolean acceptsPositiveButtonPress()

Overwrite and return false from this function if you don't want the dialog to be closed yet, for example due to an invalid user input.

protected void pressPositiveButton()

Simulates a positive button press e.g. due to an IME action.

protected void setPositiveButtonEnabled(boolean enabled)

Updates the positive button state.

Examples

For exemplary use have a look at the following dialogs (which extend CustomViewDialog):

Clone this wiki locally