自定义控件,设置databinding无效
在xml中为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="@color/whiteColor">
<ImageView
android:id="@+id/tvImage"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="-10dp"
android:visibility="gone" />
<TextView
android:id="@+id/tvLeftText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dp_15"
android:layout_toRightOf="@id/tvImage"
android:gravity="center"
android:text="朋友圈"
android:textSize="15sp" />
<TextView
android:id="@+id/tvRightText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/dp_15"
android:drawableRight="@mipmap/icon_go_arrow"
android:gravity="center" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:background="#EBEBEB" />
</RelativeLayout>
自定义对象为 其它代码简略,
public class CommonViewItem extends RelativeLayout {
public void setText_left(CharSequence text) {
leftTextView.setText(textLeft);
leftTextView.setTextColor(colorBlack);
}
public void setText_right(CharSequence text) {
rightTextView.setText(textLeft);
rightTextView.setTextColor(colorBlack);
}
}该自定义控件可以正常使用以后,想使该控件可以使用databinding的功能,该控件里面封装了两个textview,自定义bindingAdatper为:public class DataBindingAdapta {
@BindingAdapter({"bind:text_left","bind:text_right"})
public static void entries(CommonViewItem operator, String array, String array2) {
operator.setText_left(array);
operator.setText_right(array2);
}
}
定义好以后,
<com.android.base.ui.widget.CommonViewItem
android:id="@+id/myItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
bind:rightIsVisiable="true"
bind:text_left="@{user.userName}"
bind:text_right="@{user.userName}" />
调用该控件,在自定义的类(CommonViewItem)中的setText_left()方法可以正常调用,并且传入了正确的值,但是代码调用以后其中的setText执行后,页面没有赋值成功。
请指导一下,错误在哪。