如何使用 Android 双向绑定在 EditText 中设置正则表达式?
how to set regex in EditText with Android two way binding?
您好,我想知道如何使用 Android 双向绑定
在 EditText 中设置正则表达式
我的正则表达式
val VALID_PASSWOLD_REGEX_ALPHA_NUM: Pattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&])[A-Za-z[0-9]$@$!%*#?&]{8,32}$")
我的视图模型
val passwordText = MutableLiveData<String>("")
我的xml
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@null"
android:onTextChanged="@{(text, start, before, count) -> signUpViewModel.onPasswordChanged(text)}"
android:hint="@string/sign_up_password"
android:text="@={signUpViewModel.passwordText}"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/name_text" />
我简短的想法是应该从 onTextChange 接收并处理,但我想不出更好的方法,所以我问这个问题
能否请您介绍一下其他方式?
我刚刚使用 android:onTextChanged 完成了谢谢
您好,我想知道如何使用 Android 双向绑定
在 EditText 中设置正则表达式我的正则表达式
val VALID_PASSWOLD_REGEX_ALPHA_NUM: Pattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&])[A-Za-z[0-9]$@$!%*#?&]{8,32}$")
我的视图模型
val passwordText = MutableLiveData<String>("")
我的xml
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@null"
android:onTextChanged="@{(text, start, before, count) -> signUpViewModel.onPasswordChanged(text)}"
android:hint="@string/sign_up_password"
android:text="@={signUpViewModel.passwordText}"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/name_text" />
我简短的想法是应该从 onTextChange 接收并处理,但我想不出更好的方法,所以我问这个问题
能否请您介绍一下其他方式?
我刚刚使用 android:onTextChanged 完成了谢谢