0

Ich habe gerade angefangen, mit Android data-binding zu arbeiten. Und ich wollte Button-Text entsprechend Benutzer Login-Status ändern, aber ich habe unter Fehler.Android - Wie man eigenen Text in Button/TextView mit Datenbindung

Log sagt Syntaxfehler, versuchte, aber ich fand nichts.
-Code
enter image description here

Logcat Fehler

Error:|', '?', ':', '??'} Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Syntax error: mismatched input 'gin' expecting {'.', '::', '[', '+', '-', '*', '/', '%', '<<', '>>>', '>>', '<=', '>=', '>', '<', 'instanceof', '==', '!=', '&', '^', '|', '&&', '||', '?', ':', '??'} file:C:\Users\user\AndroidStudioProjects\Test\app\src\main\res\layout\binding_activity.xml loc:30:28 - 30:61 ****\ data binding error ****

Jede Hilfe appriciated wird ..

Antwort

2

Ihre Schreibweise sollte wohl sein wie:

user.isLogged ? @string/logout : @string/login 
2

Wie Sherlock sagt "You see, but you do not observe. The distinction is clear"

Und was ich tat, ich habe nicht das offizielle Dokument beobachtet. Sie können Text wie dieser auch

When using single quotes around the attribute value, it is easy to use double quotes in the expression:

android:text='@{user.isLogged ? "Logout" : "Login"}' 

It is also possible to use double quotes to surround the attribute value. When doing so, String literals should either use the quote or back quote (`).

android:text="@{user.isLogged ? `Logout` : `Login`}" //text is inside back-quote 

Data Binding Guide- String Literals

happyCoding gesetzt;

Verwandte Themen