我正在为我的自定义字段使用数据绑定(bind)。我为此设置了自定义数据绑定(bind)适配器。
我的绑定(bind)适配器如下所示:
@BindingAdapter({"created_by,created_at"})
public static void setDetailCreated(TextView textView, String createdBy, long createdAt) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(createdAt);
SimpleDateFormat dateFormat = new SimpleDateFormat("h:mm a, dd MMM yyyy");
String format = textView.getContext().getString(R.string.details_created, createdBy,
dateFormat.format(cal.getTime()));
textView.setText(format);
}
在我的布局文件中我有:
...
<data>
<import type="java.util.Map" />
<import type="com.example.beans.Friend" />
<variable
name="user"
type="com.example.beans.User" />
<variable
name="friends"
type="Map<String, Friend>" />
</data>
....
....
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:created_by="@{friends[user.createdBy].name}"
app:created_at="@{user.createdAt}" />
但是在运行时出现以下错误:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.RuntimeException: failure, see logs for details. BindingAdapter setDetailCreated(android.widget.TextView,java.lang.String,long): old values should be followed by new values. Parameter 2 must be the same type as parameter 3.
我不明白这里出了什么问题?
最佳答案
错误在你的BindingAdapter
中,应该是
@BindingAdapter({"created_by","created_at"})
public static void setDetailCreated(TextView textView, String createdBy, long createdAt){
}
所有值都应该用逗号分隔并用双引号引起来。
关于android - 数据绑定(bind)错误 : old values should be followed by new values. 参数 2 必须与参数 3 的类型相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39374874/