【问题标题】:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.(Android/Kotlin)java.lang.IllegalStateException:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView()。(Android/Kotlin)
【发布时间】:2019-12-08 21:04:57
【问题描述】:

我在警报对话框中收到上述错误,但不知道为什么或如何解决它。 我相信它源于下面的功能。 基本上,当在我的应用程序中,导航到详细信息片段,然后单击应用程序中的发送按钮以共享应用程序崩溃的 SMS。 请看一下我的代码。任何帮助表示赞赏。

           if (sendSmsStarted && permissionGranted) {
               context?.let {
                   val smsInfo = SmsInfo(
                       "",
                       "${currentDog?.dogBreed} bred for ${currentDog?.bredFor}",
                       currentDog?.imageUrl
                   )

                   val diaologBinding: SendSmsDiaologBinding =
                       DataBindingUtil.inflate<SendSmsDiaologBinding>(
                           LayoutInflater.from(it),
                           R.layout.send_sms_diaolog, null, false
                       )

                   androidx.appcompat.app.AlertDialog.Builder(it).setView(databinding.root)
                       .setPositiveButton("Send SMS") { dialog: DialogInterface, which ->
                           if (!diaologBinding.smsInfo.toString().isNullOrEmpty()) {
                               smsInfo.to = diaologBinding.smsInfo.toString()
                               sendSms(smsInfo)
                           }
                       }

                       .setNegativeButton("Cancel") { dialog: DialogInterface, which -> }
                       .show()

                   diaologBinding.smsInfo = smsInfo


               }
           }
       }```

【问题讨论】:

标签: android kotlin


【解决方案1】:

我相信您打算使用新膨胀的diaologBinding.root 而不是databinding.root 作为对话框视图。后者看起来像是您已经用于其他目的的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    相关资源
    最近更新 更多