Cannot find the setter for attribute with parameter

前端 未结 7 2184
轮回少年
轮回少年 2020-12-18 18:52

I am working on DataBinding with BindingAdapter. Here is my custom method.

@BindingAdapter(\"{bind:fadevisible}\")
public static vo         


        
相关标签:
7条回答
  • 2020-12-18 18:55

    Your @BindingAdapter definition looks a little bit odd to me

    @BindingAdapter("{bind:fadevisible}")
    

    This is not the same like

    @BindingAdapter({"bind:fadevisible"})
    

    or

    @BindingAdapter("bind:fadevisible")
    

    which should work perfectly fine.

    0 讨论(0)
  • 2020-12-18 18:58

    Make sure in app level gradle, you have apply plugin: 'kotlin-kapt'

    0 讨论(0)
  • 2020-12-18 19:04

    I had initially set defined my customBindidingAdapter as private:

    @BindingAdapter("setPriorityColor")
    private static void getPriorityColor(TextView textView, int priority) {
    }
    
    0 讨论(0)
  • 2020-12-18 19:05

    You try

     @BindingAdapter("bind:fadevisible")
    
    0 讨论(0)
  • 2020-12-18 19:11

    I had this problem with binding to ImageView and unlike your case, the definition of my binding adapter was correct but still, the IDE kept giving me this error message. After spending many hours on searching for the cause, I figured that the namespace that I use in xml layout file needs to be exactly what I declared in @BindingAdapter.

    So, if my xml is like below:

    <ImageView
        android:id="@+id/logo"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        app:image_url="@{item.logoUrl}"
    />
    

    Then my binding method should be as below:

    @BindingAdapter({"app:image_url"})
    public static void loadImage(ImageView view, String logoUrl) {
        if (logoUrl == null) {
            view.setImageResource(R.drawable.ic_place_holder);
        } else {
            Glide.with(getContext()).load(logoUrl).crossFade().into(view);
        }
    }
    

    Note that binding method annotation indicates the namespace in it , i.e. @BindingAdapter({"app:image_url"}) exactly as it is used in layout file app:image_url="@{item.logoUrl}"

    So unlike what is said in most tutorials, don't use @BindingAdapter({"bind:image_url"}) in your binding method and app:image_url="@{item.logoUrl}" in your xml file.

    0 讨论(0)
  • 2020-12-18 19:16

    Add on to the answers if you are working on multiple modules then where you have

     @BindingAdapter("fadevisible")
    

    That module should have the following code in the module -> build.gradle.

    dataBinding {
        enabled = true
    }
    

    Enjoy Happy coding. :)

    0 讨论(0)
提交回复
热议问题