gpt4 book ai didi

android - 带有 Dagger 的 AlertDialog - 您必须先在 child 的 parent 上调用 removeView() - Android

转载 作者:行者123 更新时间:2023-11-29 23:25:39 26 4
gpt4 key购买 nike

我正在使用 AlertDialogDagger,如下所示:

@Module(includes = {
WorkTableFragmentModule.WorkTableAPIViewAbstractModule.class,
RemoteAPIDataModule.class
})
public class WorkTableFragmentModule {
...Some code...
@Provides
final AlertDialog.Builder alertDialogAccess(WorkTableFragment workTableFragment) {
return new AlertDialog.Builder(Objects.requireNonNull(workTableFragment.getActivity()));
}
@Provides
LayoutInflater layoutInflater(WorkTableFragment workTableFragment) {
return Objects.requireNonNull(workTableFragment.getActivity()).getLayoutInflater();
}
@Provides
View viewDialogAccess(LayoutInflater layoutInflater) {
final ViewGroup nullParent = null;
return layoutInflater.inflate(R.layout.dialog_access_share, nullParent);
}
}

Fragment 如下所示:

public class WorkTableFragment extends DaggerFragment{
@Inject
AlertDialog.Builder alertDialogAccess;
@Inject
View accessAlertDialogView;
@Inject
LayoutInflater inflater;

private void accessAlertDialog() {
if (getActivity() != null && isAdded()) {
alertDialogAccess.setCancelable(false);
new DialogViewHolderAcceptShare(accessAlertDialogView);
alertDialogAccess.setView(accessAlertDialogView);
dismissAccessDialog = alertDialogAccess.show();
}
}
}

但是让我报错:

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4656)
at android.view.ViewGroup.addView(ViewGroup.java:4497)
at android.view.ViewGroup.addView(ViewGroup.java:4469)
at android.support.v7.app.AlertController.setupCustomContent(AlertController.java:657)
at android.support.v7.app.AlertController.setupView(AlertController.java:475)
at android.support.v7.app.AlertController.installContent(AlertController.java:233)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:279)
at android.app.Dialog.dispatchOnCreate(Dialog.java:642)
at android.app.Dialog.show(Dialog.java:341)
at android.support.v7.app.AlertDialog$Builder.show(AlertDialog.java:1007)
at xx.xx.xx.fragments.worktablefragment.WorkTableFragment.accessAlertDialog(WorkTableFragment.java:343)
at xx.xx.xx.fragments.worktablefragment.WorkTableFragment.onRequestPermissionsResult(WorkTableFragment.java:409)
at android.support.v4.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:860)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7434)
at android.app.Activity.dispatchActivityResult(Activity.java:7260)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4468)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515) 
at android.app.ActivityThread.-wrap22(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

最佳答案

像下面这样解决了我的问题:

private void accessAlertDialog() {
if (getActivity() != null && isAdded()) {
if (dismissAccessDialog == null) {
alertDialogAccess.setCancelable(false);
new DialogViewHolderAcceptShare(accessAlertDialogView);
alertDialogAccess.setView(accessAlertDialogView);
dismissAccessDialog = alertDialogAccess.show();
}else {
dismissAccessDialog.show();
}
}
}

关于android - 带有 Dagger 的 AlertDialog - 您必须先在 child 的 parent 上调用 removeView() - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53613474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com