San Jaisy San Jaisy - 5 months ago 37
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

RRR RRR
Answer

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}"