当你在Dialog xml里面使用onClick方法时发现报java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class androidx.appcompat.widget.AppCompatTextView with id
怎么会这样呢??
报错堆栈信息如下:
图1
发现报错出现在View的resolveMethod方法里面,打开该方法源码
图2
原来是查找Context(包括其子类)类种是否有该方法实现,而dialog并为实现或者继承任何Context类,所有不会去该类中去搜索,所以就找不到