2

Good day, I am practising my skills using layout, just learned data binding, and I want to know how I can use a variable like defaultName within a textview, so I am trying to do this:

android:text="@={`hi `+ myName.defaultName}"

I want the output to be:

hi Travis Scott

But instead I get a nasty error which is this:

cannot find symbol class ActivityMainBindingImpl
import com.example.nickname.databinding.ActivityMainBindingImpl;
[databinding] {"msg":"The expression \u0027(\"hi \") + (myNameDefaultName)\u0027 cannot be inverted, so it cannot be used in a two-way binding\n\nDetails: Two-way binding with string concatenation operator (+) only supports the empty string constant (`` or \"\")","file":"app\\src\\main\\res\\layout\\activity_main.xml","pos":[{"line0":27,"col0":25,"line1":27,"col1":49}]}
                                       ^

I researched the error, I didn't find the solution. I researched what alternatives people have used to this problem and I didn't find anything. The only thing I found was this "@={hi + myName.defaultName}" and that's it.

meniman98
  • 195
  • 1
  • 13

1 Answers1

2

You are trying to two-way binding instead of one-way binding. Just remove "=" sign and change braskets

android:text='@{"hi" + item.title}'
i30mb1
  • 3,894
  • 3
  • 18
  • 34
  • 1
    Goodness, that solved the issue. I got rid of the "=" and it worked. Now it says exactly what I need it to say, thank you so much! – meniman98 Jan 21 '21 at 17:56