kir*_*403 5 data-binding android android-databinding
我正在为我的自定义字段使用数据绑定.我为此设置了自定义数据绑定适配器.
我的绑定适配器看起来像这样:
@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);
}
Run Code Online (Sandbox Code Playgroud)
在我的布局文件中,我有:
...
<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}" />
Run Code Online (Sandbox Code Playgroud)
但在运行时我收到以下错误:
错误:任务':app:compileDebugJavaWithJavac'的执行失败.java.lang.RuntimeException:失败,请参阅日志以获取详细信息.BindingAdapter setDetailCreated(android.widget.TextView,java.lang.String,long):旧值后面应该跟新值.参数2必须与参数3的类型相同.
我不明白这里出了什么问题?
Rav*_*avi 13
错误在你的内部BindingAdapter,它应该是
@BindingAdapter({"created_by","created_at"})
public static void setDetailCreated(TextView textView, String createdBy, long createdAt){
}
Run Code Online (Sandbox Code Playgroud)
所有值应以逗号分隔并用双引号括起来.
| 归档时间: |
|
| 查看次数: |
1500 次 |
| 最近记录: |