1

I have situation where want to pass string in to custom view attribute, but it not working if not passing only a reference.

Working:

......
app:title="sa"
app:title="@string/winning_title"
......

Not working:

  <data>

        <variable
            name="title"
            type="String" />
    </data>
......

   app:title="@{title}"

And stylable:

   <declare-styleable name="CollapsibleRecyclerView">
        <attr name="title" format="string"/>
        <attr name="separatorsColor" format="color"/>
        <attr name="animationDuration" format="integer"/>
    </declare-styleable>

Any ideas how to fix it?

Antonis Radz
  • 3,036
  • 1
  • 16
  • 34

1 Answers1

1

Since you used "@{...}", I believe Android will automatically attempt to use data binding on it and look for a corresponding custom BindingAdapter.

You could define something like this and see if it works:

@BindingAdapter("app:title")
public static void setPaddingLeft(YourView view, String text) {
  view.doSomething(text);
}
limdale
  • 201
  • 1
  • 8