Databinding Error: old values should be followed by new values. Parameter 2 must be the same type as parameter 3

Databinding Error: old values should be followed by new values. Parameter 2 must be the same type as parameter 3

我正在为我的自定义字段使用数据绑定。我为此设置了自定义数据绑定适配器。

我的绑定适配器如下所示:

@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&lt;String, Friend&gt;" />

 </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){

}

所有值都应该用逗号分隔并用双引号括起来。

在 Kotlin 中,我看起来是这样的:

@BindingAdapter("created_by", "created_at")
@JvmStatic fun setDetailCreated(textView: TextView, createdBy: String, createdAt: Long){
    // do stuff
}