empty string databinding android 1

empty string databinding android

android:text='@{item.title != null ? user.title : ""}'

Here is what the above code is Doing:
1. The @{} syntax is used to bind the data to the view.
2. The item.title is the data that is being bound to the view.
3. The != null is the condition that is being checked.
4. The ? is the if operator.
5. The user.title is the value that is being set if the condition is true.
6. The : is the else operator.
7. The “” is the value that is being set if the condition is false.

The above code is equivalent to the following Java code:

if (item.title != null) {
textView.setText(user.title);
} else {
textView.setText(“”);
}

Similar Posts