San Jaisy San Jaisy - 2 years ago 114
Java Question

How to write Ternary operation condition in android XML while data binding

How to write the equivalent expression of Ternary operation in android xml while using data binding.

android:visibility="@{(assessmentquestionanswer.type.equals(@string/editText_type)? View.VISIBLE : View.GONE) || (assessmentquestionanswer.type.equals(@string/date)? View.VISIBLE : View.GONE)}"

Currently I am getting an error message as
must be able to find a common parent for boolean and int

Answer Source

Your way of implementation is wrong, your current condition is like

(assessmentquestionanswer.type.equals(@string/editText_type)?  View.VISIBLE : View.GONE) || (assessmentquestionanswer.type.equals(@string/date)?  View.VISIBLE : View.GONE)
                          View.VISIBLE                                                   ||                            View.VISIBLE

which is not right. It should be

android:visibility="@{(assessmentquestionanswer.type.equals(@string/editText_type) || assessmentquestionanswer.type.equals(@string/date)) ?  View.VISIBLE : View.GONE}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download