Bind ButterKnife to Dialog fails

butterknife androidx support
butterknife bind not working
butterknife onclick not working
butterknife in fragment
butterknife onclick multiple
how to use butterknife in androidx
oncheckedchanged (butterknife)
butterknife custom view

I try to bind ButterKnife to a AleterDialog that i made with a DialogBuilder method And exist this method ButterKnife.bind(Object,Dialog); but dosen't work for me

import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
public class NewUserDialogFragment extends DialogFragment {
    @Bind(R.id.textuserAccount)
    EditText textuserAccount;
    @Bind(R.id.textPassword)
    EditText textPassword;
    @Bind(R.id.nauta_domains)
    Spinner nauta_domains;
    @Bind(R.id.manualConfig)
    View manualConfig;
    @Bind(R.id.checkViewPass)
    CheckBox checkViewPass;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog dialog = 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();
      //Fails!!!!!!!
        ButterKnife.bind(this,dialog);  
    ...

ERROR:

Caused by: java.lang.IllegalStateException: Required view 'textuserAccount' with ID 2131624044 for field 'textuserAccount' was not found. If this view is optional add '@Nullable' annotation.
                                                                                      at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)

and textuserAccount = (EditText) ((Dialog) dialog).findViewById(R.id.textuserAccount); works perfectly

I can use butterknife somehow in this class?

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.

android - Bind ButterKnife to Dialog fails, I try to bind ButterKnife to a AleterDialog that i made with a DialogBuilder method And exist this method ButterKnife.bind(Object,Dialog); but dosen't work for me null is being returned from Android's Resources class. Doesn't really seem to have anything to do with ButterKnife. Try loading the resources manually in the same place you're calling ButterKnife.bind and see if they come back null as well. This comment has been minimized.

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();
}

Resource binding fails in DialogFragment � Issue #346 , @Override public Dialog onCreateDialog() { View view = View.inflate(); ButterKnife.bind(this, view); } }. Hi, I am having an AlertDialog which is opened on click of a RecyclerView ListItem and want to bind the views in the AlertDialog using Butterknife. For now I am binding the views at class level but it is giving null pointer.

And everything works perfect

Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.dialog_outcome); Unbinder unbinder = ButterKnife.bind(this, dialog);

Bind Views of AlertDialog in Activity � Issue #889 � JakeWharton , For now I am binding the views at class level but it is giving null pointer. on click of a RecyclerView ListItem and want to bind the views in the AlertDialog using Butterknife. Please provide a full failing sample or test case. Binding can be performed directly on an activity, a view, or a dialog. Alternate objects to bind can be specified along with an activity , view , or dialog . Group multiple views together into a List or array.

Butter Knife, Field and method binding for Android views. Annotate fields with @BindView and a view ID for Butter Knife to find and automatically cast the corresponding� Butterknife includes also findById methods which simplify code that still has to find views on a View, Activity, or Dialog. It uses generics to infer the return type and automatically performs the cast.

ButterKnife (butterknife 10.2.1 API), public final class ButterKnife extends java.lang.Object. Field and Binding can be performed directly on an activity, a view, or a dialog. Alternate objects to bind� Dialog-A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for model events that require users to take an action before they can proceed. When are we creating our application by using Data Binding then how we use Data Binding in a custom dialog?

Bind ButterKnife to Dialog не работает Oh! Android, Я пытаюсь связать ButterKnife с AleterDialog, который я сделал с помощью метода DialogBuilder. И существует этот метод ButterKnife.bind(Object� Android Butterknife vs Data Binding. Lets compare Butterknife and Data Binding libraries, which one is more advanced as of now. If you’re not familiar with those two, in few words: they make your layout building experience better. And when comparing them I’ll go right from setting up and cover every basic aspect so you’ll learn how to use

Comments
  • OK the final solution is pass this inflated view to dialog : new AlertDialog.Builder(getActivity())...setView(view)
  • Fixed my problem. Thanks bud.