问题标签 [android-binding-adapter]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
4084 浏览

android - 自定义视图上的两种方式绑定

我在 android 中有一个组合视图,其中包含几个 textView 和一个 EditText。我为我的自定义视图定义了一个名为textand方法getText的属性。setText现在我想以绑定到内部编辑文本的方式为我的自定义视图添加 2 路数据绑定,因此如果我的数据得到更新,编辑文本也应该更新(现在可以使用),当我的编辑文本得到更新时,我的数据也应该更新。

我的绑定类看起来像这样

我试图用下面的代码绑定文本。userInfo是一个可观察的类。

当我运行项目时出现此错误

错误:(20, 13) 在视图类型“ir.avalinejad.pasargadinsurance.component.ErrorInputLayout”上找不到事件“textAttrChanged”

我的自定义视图看起来像这样

0 投票
1 回答
8047 浏览

android - 具有多个参数的数据绑定绑定适配器不起作用

我正在尝试使用数据绑定来加载具有多个参数的 Glide、Imageview 和 Bindingadapter 的图像:

bindingadapter 方法是顶级函数。编译时出现数据绑定-kapt 错误“在 android.widget.ImageView 上找不到参数类型为布尔型的属性 'app:circleCrop' 的设置器”,就好像我的 bindingadapter 无法识别一样。不知道我做错了什么

0 投票
1 回答
1577 浏览

android - 如何在 DataBinding Android 的 BindingAdapter 方法中提供默认值

我正在研究一种绑定适配器方法来设置颜色跨度TextView

这是我如何使用它

我似乎无法获得end指定为文本最后索引的 as 参数默认值TextView

是否有任何解决方法可以用来从参数中获取默认值,而无需检查该值是否为 0?

0 投票
1 回答
546 浏览

android - 从改造获得响应后如何更新 Imageview(android 数据绑定)

以下是布局文件:我正在使用自定义设置器,即 BindingAdapter

pic 将获得 int 值,该值将设备的状态为布尔值。

这是我的绑定适配器:

现在我在绑定适配器执行后得到了改造的响应,那么如何通知绑定我有数据并更新视图并再次调用绑定适配器?

0 投票
4 回答
5949 浏览

android - Android - 绑定适配器不起作用

我创建了一个绑定适配器来用毕加索显示图片,但它不起作用。我有以下错误:

发现数据绑定错误。****/ 数据绑定错误 ****msg:在 android.widget.ImageView 上找不到参数类型为 java.lang.String 的属性“app:loadPicture”的设置器。文件:/home/groupevsc.com/mathieu_labar/Documents/Projects/android-jetpack/app/src/main/res/layout/activity_detail_movie.xml 位置:27:31 - 27:52 ****\ 数据绑定错误 * ***

这是我的绑定适配器:

我的 XML 有属性 "app:loadPicture" :

这是我的 GitHub 存储库: https ://github.com/mlabar/android-jetpack/tree/tech_ajout_databinding

有人有想法解决我的问题吗?

谢谢!

0 投票
0 回答
100 浏览

android - Android BindingAdapter 将默认行为设置为所有 TextView

我有很多布局,我想将一些默认属性设置为我所有TextViews. 例如

有没有办法做到这一点而不添加:

90% TextViews?是的,我可以创建自己的TextView,但事实并非如此。以全局样式拥有它会很好

样式似乎不支持BindingAdapter

0 投票
1 回答
1244 浏览

android - 如何使用 BindingAdapter 来更新 RecyclerView?

我在我的应用程序中使用 MVVM 和 DataBindg。我有一个问题,当从服务器接收到数据时,我的 recyclerView 适配器会不停地添加新项目。

例如,如果我收到 15 件商品,recyclerview将添加 15,然后是 30,然后是 60,...

这是我的片段视图模型:

我检查了这部分代码,这将执行一次。这是这个片段的 XML:

我还BindingAdapter用来将接收到的数据设置为我recyclerView的。这是我的 BindingAdapter 类:

最后这是我的 recyclerView 适配器,用于将接收到的数据设置到其中:

我不明白问题出在哪里。我真的很感谢你的回答。

谢谢你。

0 投票
2 回答
1505 浏览

android - BindingAdapter doesn't work with DataBinding

I've got a button:

The BindingAdapter looks as follows:

This doesn't work, it gives the following error: "Cannot find the setter for attribute 'binding:firstStringParameter' with parameter type java.lang.String on android.widget.Button.". However, if I change binding:firstStringParameter="@{vm.userName}" to, for example, binding:firstStringParameter="my lovely string" this will work.

The userName in the ViewModel is val userName: String = "my name" and if I try android:text="@{vm.userName}" that works. So the problem is in the databinding. I've got another project where I used the same code and it works... Sounds like a bug in the databinding/adaperbinding framework, but maybe someone came across this problem?

P.S. I also tried binding:firstStringParameter="@{ + vm.userName}", did not work.

By looking at the autogenerated Binding class I discovered a very strange code:

0 投票
3 回答
5115 浏览

android - 为什么这个 BindingAdapter 在 Kotlin 中不起作用?

我有一个 ViewModel:

我的布局 XML 有:

我有一个具有顶级功能的 BindingAdapters 文件:

我收到以下错误:

知道为什么会这样吗?这与我在 Java 中设置绑定适配器的方式几乎相同,只是减去了静态函数。

0 投票
0 回答
382 浏览

android - 数据绑定包不存在?

我在嵌套包默认包中有自定义视图:com.example.testing 我在子包中创建了一个自定义类视图,如 com.example.testing.login.pinview并插入到如下布局中

重建android项目后我收到错误

错误:包登录不存在

即使我已经在 gradle 中启用了数据绑定

请任何人帮助我从 2 天开始