Bind ButterKnife to Dialog fails

You need to inflate your dialog layout and pass the resulting View object to butterknife.

    view = View.inflate(getContext(), R.layout.accountlist_dialog_user_, null);
    ButterKnife.bind(this, view);

At least, that's how I've used Butterknife in dialogs and it works fine for me.


I was able to bind views in onStart of the DialogFragment (similarly to this sample app), while still using the AlertDialog.Builder#setView(int) method:

private Unbinder unbinder;

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity())
            .setIcon(R.drawable.new_user_dialog__icon)
            .setTitle(R.string.new_user_dialog_title)
            .setView(R.layout.accountlist_dialog_user)
            .setPositiveButton(R.string.alert_dialog_create, void_OnClickListener)
            .setNegativeButton(R.string.alert_dialog_cancel, void_OnClickListener)
            .create();
}

@Override
public void onStart() {
    super.onStart();
    unbinder = ButterKnife.bind(this, getDialog());
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    unbinder.unbind();
}