首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android数据库默认变量值

Android数据库默认变量值
EN

Stack Overflow用户
提问于 2018-11-12 21:06:55
回答 1查看 10K关注 0票数 7

我有这个布局。

代码语言:javascript
复制
<data>
    <import type="android.view.View" />
    <variable
        name="shouldBeVisible"
        type="java.lang.Boolean" />
</data>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="@={shouldBeVisible}" />

    <LinearLayout
        android:layout_width="40dp"
        android:layout_height="30dp"
        android:background="#dd0"
        android:visibility="@{shouldBeVisible ? View.VISIBLE : View.GONE}" />

</LinearLayout>

默认情况下,shouldBeVisible为false。有什么方法可以使shouldBeVisible 成为真呢?--我想让LinearLayout在这一种情况下可见。

到目前为止,我正在使用binding.shouldBeVisible=true

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-13 11:14:20

要解决该错误,可以使用以下几种方法:

  1. 您可以在倒置逻辑中使用原语布尔类型(shouldBeVisible -> shouldBeHidden)
  2. 第二种方法是使用装箱布尔类型(就像现在一样),并在表达式中设置默认值
  3. 第三种方式--在绑定充气后手动设置它(就像您现在已经做的那样) binding.shouldBeVisible=true
  4. 在数据库值中使用默认关键字

选择一个最适合你的需求。

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53270107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档