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?

1 Answer 1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.