DylanCaiCoding/ViewBindingKTX

自定义View和主界面id冲突问题

ivotai opened this issue · 0 comments

自定义 View 里有个 MaterialTextView,id 是 tv。
主界面 Activity 布局中使用了上述自定义 View,且布局里本身有个 RTextView,id 也是 tv。

然后报错如下:
Caused by: java.lang.ClassCastException: com.google.android.material.textview.MaterialTextView cannot be cast to com.ruffian.library.widget.RTextView

猜测是 inflate 的过程中因为 id 一样 binding 错了。
修改自定义View中 id 为 ctv 加以区分后,报错不再复现。