Bind ButterKnife to Dialog fails

后端 未结 3 1394
忘掉有多难
忘掉有多难 2021-02-07 11:34

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<

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 12:30

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

提交回复
热议问题