当有人开始在 EditText 中书写时,我试图启用该按钮。
我将按钮的启用属性设置为android:enabled ="@{editText.text.length() > 0}"
这工作得很好。但是当我尝试使用两种方式数据绑定将 EditText 绑定到 ViewModel 时它停止工作。
正是这条线产生了差异。
android:text="@={signUpViewModel.Phone}"
Run Code Online (Sandbox Code Playgroud)
没有这个,它工作正常!可能是什么原因?
下面是完整的 XML。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="signUpViewModel"
type="com.qenetech.africapuzzle.signup.SignUpViewModel" />
<variable
name="editText_verify_phone_number"
type="android.widget.EditText" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".signup.verify_phone.EnterPhoneFragment">
<Spinner
android:id="@+id/spinner_country"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10"
app:layout_constraintEnd_toEndOf="@+id/spinner_country"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/spinner_country"
app:layout_constraintTop_toBottomOf="@+id/spinner_country">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:textColorHint="@android:color/darker_gray">
<android.support.design.widget.TextInputEditText
android:id="@+id/editText_verify_phone_country_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="@={signUpViewModel.CountryCode}"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/etPhoneLayout"
android:layout_width="0dp"
android:layout_weight="8" …Run Code Online (Sandbox Code Playgroud) data-binding android mvvm android-databinding android-viewmodel