如何打开数据绑定?

时间:2016-09-19 09:27:53

标签: android data-binding android-databinding

我见过this code in one of Google's Android examples。这里的代码示例:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <import type="android.view.View" />

        <variable
            name="stats"
            type="com.example.android.architecture.blueprints.todoapp.statistics.StatisticsViewModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            <!-- look at this -->
            android:text="@{stats.status}"
            android:visibility="@{stats.showStatus ? View.VISIBLE : View.GONE}" />
    </LinearLayout>
</layout>

我想在我自己的项目中使用这样的东西,但它没有编译。我想它需要一些库或其他东西,但我找不到它。有什么建议吗?

1 个答案:

答案 0 :(得分:4)

UserWidget = { 'controller' : function(){ this.users = User.load(); }, 'view' : function(ctrl) { if (ctrl.users()) return m('.user', ctrl.users()[0].name()); } } //initialize m.module(document.body, UserWidget);

中启用dataBinding
build.gradle