隐藏基于属性

时间:2017-05-18 16:27:32

标签: android android-layout android-studio android-fragments

我想基于属性值隐藏textView。有一个' creditCard'模型对象作为变量导入到xml布局中

  <TextView
      android:text="@={ creditCard.name }"
      android:visibility="@{ creditCard.name}" />

这是基于属性值null / empty显示/隐藏视图元素的正确方法吗?

1 个答案:

答案 0 :(得分:2)

<TextView
      android:text="@={ creditCard.name }"
      android:visibility="@{ creditCard.hasName()}" />

您在CreditCard类中的方法应该是这样的;

public int hasName(){
      return TextUtils.isEmpty(mName) ? View.GONE : View.VISIBLE
}

祝你好运

埃姆雷