jjzjj

BindingAdapter

全部标签

android - 使用 Android 数据绑定(bind)时如何访问 BindingAdapter 中的实例变量?

所以我使用这个流行的数据绑定(bind)代码fragment通过传入URL将图像加载到列表项的ImageView中:绑定(bind)适配器:classMovie{booleanisLoaded;@BindingAdapter({"bind:imageUrl"})publicstaticvoidloadImage(finalImageViewview,StringimageUrl){Picasso.with(view.getContext()).load(imageUrl).into(view,newCallback.EmptyCallback(){@Overridepublicvoid

java - 为什么 BindingAdapter 必须是静态方法?

我刚刚学习如何在Android上使用数据绑定(bind)。我想问为什么BindingAdapter必须设置为静态方法?如果我能让它成为非静态方法。我必须做什么?我需要将我的图像加载到我自己的ImageLoader对象中。 最佳答案 BindingAdapter不必是静态的。如果它是静态的,使用起来会容易得多。如果您必须使用实例方法,您可以,但您必须提供一种通过DataBindingComponent访问实例的方法。假设您有一个BindingAdapter实例:publicclassImageBindingAdapters{priva

android - BindingAdapter 自定义 getter 2 方式数据绑定(bind)

我创建了一个自定义setter,将枚举的文本设置为editText:publicenumGender{MALE,FEMALE}XML:适配器:@BindingAdapter("custom:holder")publicstaticvoidsetHolder(EditTexteditText,Gendergender){editText.setText(gender.toString());}来自代码:binder=DataBindingUtil.bind(getView());binder.setUser(user);如何指定一个返回Gender对象的getter?我尝试了下面的代码,

Android dataBinding - @BindingAdapter 自定义应用命名空间被忽略

我在android中创建了一个自定义bindingAdapter,当我传入颜色时,我希望颜色发生变化,这实际上是为了测试我正在进行的工作,只是为了确保它能正常工作。这是代码:这是我的数据绑定(bind)View模型:publicclassUser{publicObservableIntvisible;publicUser(intvisible){this.visible=newObservableInt(visible);}@BindingAdapter({"app:bindColor"})//noticethebindColorcustomattributepublicstaticv

android - 将 BindingAdapter 与资源中的字符串数组结合使用

我有一个几乎简单的想法:我想使用数据绑定(bind)API和BindingAdapter为微调器生成一个适配器。这是我要使用的XML:这里的地址是一个简单的类,它有一个名为country的字段,它是一个字符串,将包含一个ISO-3166-2字符串。为简单起见,值将为“DE”或“US”。这是我简化的arrays.xml:DEUS@string/country_DE@string/country_US对于绑定(bind),我写了这个BindingAdapter:@BindingAdapter({"value","data","keys"})publicstaticvoidgenerateA

android - 在我通过 gradle 分发库后,我在库模块中创建的 BindingAdapter 无法从任何应用程序模块访问

我最近创建了一个库,并在其中创建了一个类似于下面的BindingAdapter(只是在TextView上装饰文本)。@BindingAdapter({"decorateText"})publicstaticvoiddecorateText(finalViewview,Stringtext){((TextView)view).setText(">>");}这个BindingAdapter可以从同一个AndroidStudio项目中的应用程序模块访问,如下所示但在我通过jcenter分发库并通过gradle从不同的应用程序项目导入库后,我无法使用"app:decorateText"标签。我

android - 是否可以使用 BindingAdapter 直接将事件绑定(bind)到 Observable 字段?

我正在为android-support-design库提供的底页编写一个绑定(bind)适配器。我想要实现的是将状态更改事件绑定(bind)到一个可观察字段,从而完全避免事件处理程序的胶水代码。publicclassBottomSheetBindingAdapter{@BindingAdapter("behavior_onStateChange")publicstaticvoidbindBottomSheetStateChange(finalViewview,finalObservableIntstate){finalBottomSheetBehaviorbehavior=Bottom

Android `@BindingAdapter` setter 未被调用

这是我的BindingAdapter:publicclassBindings{@BindingAdapter({"font"})publicstaticvoidsetFont(TextViewtextView,StringfontName){textView.setTypeface(FontCache.getInstance(textView.getContext()).get(fontName));}}*我没有使用“font”作为注释参数,而是尝试了“bind:font”、“android:font”和“app:font”,并在布局中进行了所有相应的更改,但是BindingAdapt

android - 如何使用 Picasso 设置 @BindingAdapter?

我想使用绑定(bind)创建电影海报图像的GridView。我的View模型看起来像这样:publicclassPopularMoviesViewModelextendsBaseObservable{Moviemovie;Contextcontext;MovieServiceComponentmovieServiceComponent=DaggerMovieServiceComponent.builder().contextModule(newContextModule(context)).build();PicassogetPicasso=movieServiceComponent.

安卓数据绑定(bind) : BindingAdapter vs InverseBindingAdapter

两者有什么区别?什么时候应该使用其中之一?当我定义一个BindingAdapter时,我是否必须创建一个反函数? 最佳答案 引用我自己的话,来自TheBusyCoder'sGuidetoAndroidDevelopment:Two-waybindingworkswellincaseswherethewayyoustorethedatainthemodelslinesupwellwiththegettersandsettersoftheassociatedwidget.Abooleanfieldinthemodelworkswellw
12