Cannot understand... How to set some property of view only if variable field isn\'t null?
For example
Well data binding avoids NullPointerException in general by checking for it and assigns the default value (null for example) even if item
itself is null in your example.
But a basic example for null checks for the item's properties:
android:text='@{item.title != null ? user.title : ""}'
Or use the "Null Coalescing Operator". The null coalescing operator (??
) chooses the left operand if it is not null or the right if it is null.
android:text='@{item.title ?? ""}'
Note that title
or getTitle
doesn't matter.