I have a boolean variable in my data-object, and want to show 1 string from resources when it is true, and another when it is false. I am trying to do it this way:
android:text="@{sendit.bccMode ? @string/sharebox.bcc_mode_on : @string/sharebox.bcc_mode_off}"
But getting an compilation error:
****/ data binding error ****msg:Could not find accessor java.lang.String.bcc_mode_on
What do I am doing wrong?
The main advantages of viewbinding are speed and efficiency. It has a shorter build time because it avoids the overhead and performance issues associated with DataBinding due to annotation processors affecting DataBinding's build time.
With data binding, a change to an element in a data set automatically updates in the bound data set. Data binding may be used for many reasons, such as to link an application's user interface (UI) and the data it displays, for data entry, reporting and in text box elements.
The Databinding
library is lost when you use the . (dot) as a name, change your strings.xml
file to this:
<string name="sharebox_bcc_mode_on">BCC mode on</string>
<string name="sharebox_bcc_mode_off">BCC mode off</string>
To be exact, you don't have to rename your strings with an underscore in place of a dot, just replace dots by underscores when you USE this string :
in the file strings.xml :
<string name="sharebox.bcc.mode.on">BCC mode on</string>
<string name="sharebox.bcc.mode.off">BCC mode off</string>
in the databinding (in activity.xml) :
android:text="@{sendit.bccMode ? @string/sharebox_bcc_mode_on : @string/sharebox_bcc_mode_off}"
So you just have to convert '.' to '_' when you use this strings in databinding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With