使用DataBinding后,编译提示找不到BR类

土豆片子 2017-01-09 05:24:15
在apapter中使用了DataBinding,编写的时候没有提示异常,但在运行时提示找不到BR类。
在build.gradle文件中有
dataBinding{
enabled true
}


Adapter中:

import com.tool.room.BR;


@Override
public ConsumeListAdapter.MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

ViewDataBinding dataBinding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()),
R.layout.detail_consume_list_item,viewGroup,false);
MyViewHolder myViewHolder = new MyViewHolder(dataBinding.getRoot());
myViewHolder.setDataBinding(dataBinding);
return myViewHolder;
}

@Override
public void onBindViewHolder(ConsumeListAdapter.MyViewHolder myViewHolder, int i) {

ConsumeBean bean = mList.get(i);
myViewHolder.getDataBinding().setVariable(BR.bean,bean);
myViewHolder.getDataBinding().executePendingBindings();
}




Xml中

<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>

<variable
name="bean"
type="com.tool.room.bean.ConsumeBean"/>

<import type="com.tool.room.utils.DataBindingUtil"/>
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@{bean.time}"
android:textColor="@color/context_text_color"
android:textSize="@dimen/sp_13"/>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@{DataBindingUtil.getConsumeTypeById(bean.type)}"
android:textColor="@color/context_text_color"
android:textSize="@dimen/sp_13"/>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@{bean.money}"
android:textColor="@color/context_text_color"
android:textSize="@dimen/sp_13"/>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@{bean.remark}"
android:textColor="@color/context_text_color"
android:textSize="@dimen/sp_13"/>
</LinearLayout>
</layout>
...全文
2452 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
uiiee 2019-10-17
  • 打赏
  • 举报
回复
编译器本来就有问题,有一次,我建了一个package,名称的首字母大写,然后用Databinding,然后install时候报错,然后 我把package名称改成首字母小写,就过了。
wisely3 2017-03-06
  • 打赏
  • 举报
回复
https://my.oschina.net/wiselyming/blog/852956 这是我写的 但是我在Android Studio2.3上面不行, 不知道为什么,如果你有stackoverflow的账户,帮我去那个高票答案下面留个言,问下为什么
内容概要:本文提出一种基于鱼鹰优化算法(OOA)优化的CNN-BiGUR-Attention混合模型,用于提升短期风电功率预测的精度与稳定性,采用Matlab实现代码仿真。该模型融合卷积神经网络(CNN)提取输入数据的局部空间特征,利用双向门控循环单元(BiGUR)捕捉风速、功率等时间序列的前后向动态依赖关系,并引入注意力机制自适应强化关键时间步的特征权重,从而增强模型对非平稳风电数据的表征能力;进一步,采用OOA算法对模型超参数进行全局寻优,有效提升模型收敛速度与泛化性能。研究基于实际风电场历史数据开展实验验证,结果表明,该方法相较传统模型在预测精度、鲁棒性和误差抑制方面表现更优,适用于高比例可再生能源接入背景下的电力系统调度需求。; 适合人群:从事新能源发电预测、电力系统优化调度、智能算法与深度学习融合应用等方向的科研人员及工程技术人员,尤其适合具备Matlab编程能力、熟悉时间序列建模与深度学习框架的研究者。; 使用场景及目标:①实现风电场短期功率高精度预测,支撑电网安全稳定调度与能量管理;②为深度学习模型结构设计与智能优化算法联合调参提供实践范例;③推动人工智能技术在可再生能源预测、智能电网运行等领域的落地应用。; 阅读建议:建议结合提供的Matlab代码深入理解CNN-BiGUR-Attention网络架构搭建、注意力机制实现方式及OOA优化流程,重点关注数据预处理、模型训练与参数调优细节,可通过替换不同风电数据集进行对比实验,进一步掌握模型迁移能力与适应性。

80,489

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧