报错 Cannot find a setter for <android.widget.TextView android:text> that accepts parameter type ‘?‘

在使用 dataBinding 的过程中,使用 ObservableList 或者 ObservableMap 类型的变量给 TextView 设置 text 时报错:

Cannot find a setter for <android.widget.TextView android:text> that accepts parameter type '?'

声明如下图所示:

报错 Cannot find a setter for <android.widget.TextView android:text> that accepts parameter type ‘?‘

原因是声明 ObservableList 和 ObservableMap 的时候需要指定该 List 或者 Map 的泛型

正确的声明如下:

报错 Cannot find a setter for <android.widget.TextView android:text> that accepts parameter type ‘?‘

指定了泛型之后红线报错是需要将尖括号“<”进行转义,Android Studio 使用 Alt + 回车就可以设置了。