现象
最近在把项目重构为MVVM模式,编译的时候总是提示下面这个警告信息。虽然可以正常运行,但是每次编译都会出现。很烦人。
Error:(22, 24) 警告: Application namespace for attribute app:items will be ignored.
分析解决
我们的代码是:
@BindingAdapter("app:items")
public static void setItems(ListView listView, List<ChatMsg> items) {
ChatAdapter adapter = (ChatAdapter) listView.getAdapter();
if (adapter != null) {
adapter.refresh(items);
}
}
警告提示说,我们的命名空间"app"将会被忽略。也就说实际运行的时候,是不管这个app命名空间的。注解关注的只是app后面这个"items"。命名空间是可要可不要的。因此解决办法就是,把这个命名空间的声明删掉。即:
@BindingAdapter("items")
public static void setItems(ListView listView, List<ChatMsg> items) {
ChatAdapter adapter = (ChatAdapter) listView.getAdapter();
if (adapter != null) {
adapter.refresh(items);
}
}
我们再重新编译,果然,这个警告就没有了。
在项目重构为MVVM模式过程中,遇到编译警告:Application命名空间在属性app:itemswill中将被忽略。通过调整@BindingAdapter注解中的命名空间,成功消除警告,确保编译过程顺畅。
4119

被折叠的 条评论
为什么被折叠?



