Reputation: 1359
I want to hide a textView based on a property value. There is a 'creditCard' model object imported into xml layout as a variable
<TextView
android:text="@={ creditCard.name }"
android:visibility="@{ creditCard.name}" />
Is this a right way to show/hide view elements based on property value null/empty?
Upvotes: 1
Views: 576
Reputation: 3346
<TextView
android:text="@={ creditCard.name }"
android:visibility="@{ creditCard.hasName()}" />
And your method that inside CreditCard class should look like;
public int hasName(){
return TextUtils.isEmpty(mName) ? View.GONE : View.VISIBLE
}
Good luck there
Emre
Upvotes: 2