kirtan403 kirtan403 - 2 months ago 10
Android Question

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

I am using data binding for my custom fields. I have set a custom data binding adapter for this.

My Binding Adapter looks like this:

@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);
}


And in my layout file I have:

...
<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}" />


But while running I am getting the below error:


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.


I don't understand what is going wrong here?

Answer

Error is within your BindingAdapter, it should be

@BindingAdapter({"created_by","created_at"})
public static void setDetailCreated(TextView textView, String createdBy, long createdAt){

}

all the values should be comma seperated and in double quotes.