尝试实现双向绑定 如前所述:
双向 Android 数据绑定 - 如何使用双向数据绑定来管理布局
然而在
<variable type="com.example.gideonsassoon.avariel.datamodels.Player" name="name"/>
Run Code Online (Sandbox Code Playgroud)
我收到以下消息。:
“属性缺少Android命名空间前缀较少......(Ctrl + F1)大多数Android视图在Android命名空间中具有属性。引用这些属性时,您必须包含命名空间前缀,否则您的属性将被aapt解释为只是自定义属性。同样,在清单文件中,几乎所有属性都应该在 android: 命名空间中。”
如果我尝试构建它,会将我文件中的所有 R. 以红色显示并声明它们不存在等。
我已经编辑了我的构建 gradle 文件
dataBinding.enabled = true
Run Code Online (Sandbox Code Playgroud)
完整代码到以下相关点
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowSoftInputMode="adjustPan"
tools:context="com.example.gideonsassoon.avariel.ui.MainFragmentActivity">
<data>
<variable type="com.example.gideonsassoon.avariel.datamodels.Player" name="name"/>
</data>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/viewpagerStrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"/>
</android.support.v4.view.ViewPager>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="34dp">
<TextView
android:id="@+id/tv_character_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name_colon"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textIsSelectable="false" />
<EditText
android:id="@+id/et_character_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@={player.name}"
android:layout_alignBaseline="@+id/tv_character_name"
android:layout_marginStart="15dp"
android:layout_toEndOf="@+id/tv_character_name"
android:ems="12"
android:hint="@string/character_name"
android:inputType="textPersonName" />
Run Code Online (Sandbox Code Playgroud)
啊,看来我把它作为relativeLayout。它不能是“绑定”,所以它只能是布局。不知道这会如何影响我的整个文件,但我想我们只需要看看它是如何发挥作用的。这是我的来源。但是,如果有人想对此做出回答,我们将不胜感激。
| 归档时间: |
|
| 查看次数: |
1186 次 |
| 最近记录: |