<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="listitem"
type="com.jiutong.haofahuo.entity.responseResult.GoodsRecordListResult.GoodsRecordList" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/text_size_15">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
//id 在定义接受的bean对象中 不可使用long 或者int 报错 只能使用String
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp_10"
android:text="@{listitem.id}"
android:textColor="@color/black_353535"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</layout>
1 本人使用的时候 发现只能通过setVariable设置数据
但是假如设置多个数据需求 一个是setVariable后台数据 另一个是setVariable StringUtils 会报错 (转换错误)
解决方法封装到一个对象中
通过setVariable设置把封装的对象数据设置进去
xml里面就 可以分别调用使用了
接着上面的问题 封装的getBindingView() 得到的是ViewDataBinding 需要转换特定当前activitybinding 才能设置定义的variable
(getBindingView() as ActivityAccountManageBinding?)?.apply {
this.listitem = dataResult.data
this.utisl = StringUtils
this.executePendingBindings()
}
3 databinding报找不到binding类符号
基本是xml文件问题,你定义的variable数据修改了 但是xml中引用还在用修改前的数据,没更换掉,仔细查查兄弟