在哪里放置android BindingAdapter方法? [英] Where to place android BindingAdapter method?

查看:114
本文介绍了在哪里放置android BindingAdapter方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这必须是最基本的问题,但是经过一整天的阅读教程和文档后此处,我似乎无法理解将这些方法放在何处。没有指南提到放置此东西的地方,仅提及在静态方法上使用注释。什么静态方法?不管类如何,都有任何静态方法吗?什么是好习惯?我该创建一个CustomBinding类来托管所有这些静态方法吗?

This has to be the most basic of question but after a full day of reading tutorials and the documentation here I can't seem to understand where to put these methods. None of the guides mention where this thing is placed it just mentions to use the annotation on a static method. What static method? Any static method at all regardless of class? What is a good practice? do I create a CustomBinding class to host all these static methods?

只要我有该方法具有BindingAdapter批注并且第一个参数是View,它将起作用?

So long as I have the method has a BindingAdapter annotation and the first parameter is a View, it will work?

我假设如果第一个参数的类型为View,我可以将binding属性放在任何类型的视图上,它将触发该方法吗?因此,如果我有特定的视图说EditText,这是否意味着仅当在布局文件的EditText视图中找到该属性时才调用该方法?

I assume if the first parameter is of type View I can place the binding attribute on any type of views and it will trigger the method? So if I have specific view say EditText, does this mean the method is only called when the attribute is found in an EditText view in the layout file?

推荐答案

浏览Internet之后,我终于从其中一位开发人员身上找到了一些信息。我希望他们对文档的基础知识会更加清楚。

After navigating through the internet I've finally found some info from one of the developers themselves. I wish they would have been more clear on the basics in the documentation.

引用

绑定适配器是任何类中的带注释方法用来做到这一点。通常,您会根据目标View类型将适配器组织为[-a]类。

这显然意味着在编译时,任何带有注解BindingAdapter的类都将生成BindingAdapter。

This obviously means that at compile time all methods in any class with the annotation BindingAdapter will generate the BindingAdapter.

这篇关于在哪里放置android BindingAdapter方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆