Rk R Bairi
Rk R Bairi

Reputation: 1359

hide an android textview based on property

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

Answers (1)

Emre Akt&#252;rk
Emre Akt&#252;rk

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

Related Questions