Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 ViewBindingUtil.inflateWithGeneric方法使用 #67

Open
stars-one opened this issue Jul 13, 2023 · 1 comment
Open

关于 ViewBindingUtil.inflateWithGeneric方法使用 #67

stars-one opened this issue Jul 13, 2023 · 1 comment

Comments

@stars-one
Copy link

用了一个对话框库(DialogX),想要结合ViewBinding一起使用,但是使用时候报错了,不太理解inflateWithGeneric方法的第一个参数是要传什么...

封装的方法代码:

 private fun <VB:ViewBinding> showDialog(onBind:(vb:VB, dialog:CustomDialog)->Unit) {
        CustomDialog.build()
            .setMaskColor(Color.parseColor("#b3000000"))
            .apply {
                //这个this是什么??
                val binding = ViewBindingUtil.inflateWithGeneric<VB>(this, LayoutInflater.from(ownActivity),RelativeLayout(ownActivity), false)

                setCustomView(object : OnBindView<CustomDialog>(binding.root) {
                    override fun onBind(dialog: CustomDialog, v: View) {
                        onBind(binding,dialog)
                    }
                })
            }.show()

    }

使用:

showDialog<DialogRateBinding> { binding, dialog ->
            //对话框的一些逻辑处理....
          
}

报错:

 java.lang.IllegalArgumentException: There is no generic of ViewBinding.
        at com.dylanc.viewbinding.base.ViewBindingUtil.withGenericBindingClass(ViewBindingUtil.kt:96)
        at com.dylanc.viewbinding.base.ViewBindingUtil.inflateWithGeneric(ViewBindingUtil.kt:45)
        at site.tx.xtproxy.util.Dialogs.showDialog(Dialogs.kt:113)
        at site.tx.xtproxy.util.Dialogs.showRate(Dialogs.kt:38)
        at site.tx.xtproxy.page.TkSettingActivity.onCreate$lambda$2(TkSettingActivity.kt:31)
        at site.tx.xtproxy.page.TkSettingActivity.$r8$lambda$UCr_uFWsiG8qCSv0LPG51z4bleM(Unknown Source:0)
        at site.tx.xtproxy.page.TkSettingActivity$$ExternalSyntheticLambda1.onClick(Unknown Source:0)

正常使用版本:

CustomDialog.build()
            .setMaskColor(Color.parseColor("#b3000000"))
            .apply {
                val binding = DialogRateBinding.inflate(
                    LayoutInflater.from(ownActivity),
                    RelativeLayout(ownActivity),
                    false
                )

                setCustomView(object : OnBindView<CustomDialog>(binding.root) {
                    override fun onBind(dialog: CustomDialog, v: View) {

                    }    
                })
            }.show()
@Airoure
Copy link

Airoure commented Mar 8, 2024

你直接用this传进去的是CommonDialog,没有泛型,肯定会报错呀。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants