First, this question is not a case of 'onClick' event parameter passing.
I have DateUtil class with one method as below :
public static String formatDate(long date) {
SimpleDateFormat dateFormat;
dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
Calendar c = Calendar.getInstance();
dateFormat.setTimeZone(TimeZone.getDefault());
c.setTimeInMillis(date);
return dateFormat.format(c.getTimeInMillis());
}
My model CommentEntity has following attributes :
private int id;
private int productId;
private String text;
private Date postedAt;
Now in one of layout I'm displaying the Comments.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="comment"
type="com.example.entity.CommentEntity"/>
<variable
name="dateUtil"
type="com.example.util.DateUtil"/>
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_alignParentRight="true"
android:layout_below="@id/item_comment_text"
//This line gives error for data binding
android:text="@{dateUtil.formatDate(comment.postedAt.time)}"/>
</layout>
The error I'm getting is :
cannot find method formatDate(com.example.util.DateUtil) in class long
Now for the same if I modify formatDate() method as it will take current time by default, hence removing the parameter passing in data binding, it will work perfectly.
So am I doing something wrong or is it a bug?
Please provide solution for problem to pass the parameter to method in data binding.