我在将 onTextChanged 添加到包含布局中的 TextInputEditText 时遇到问题。
有一个 base_edittext_view.xml 如下:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorPrimaryText"
android:background="@drawable/textinputlayout_background"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/edittextItem"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/input_border_bottom"
android:cursorVisible="true"
android:drawableEnd="@drawable/ic_user"
android:drawablePadding="@dimen/padding_medium"
android:gravity="center|left"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:maxLength="50"
android:paddingBottom="@dimen/padding_medium"
android:paddingTop="@dimen/padding_medium"
android:paddingEnd="@dimen/padding_xlarge"
android:paddingStart="@dimen/padding_medium"
android:textColor="@color/edittext_text_color"
android:textColorHint="@color/edittext_hint_text_color"
android:textSize="@dimen/textsize_medium"
/>
<!---->
</android.support.design.widget.TextInputLayout>
我想在包含 base_edittext_view.xml 的布局中添加一个 onTextChanged 侦听器。
android:onTextChanged="@{(text, start, before, count) -> viewModel.onTextChanged(text)}"
添加 onClick 以包含布局没有问题,但对于 onTextChaegd 我不知道如何实现它。
笔记:
<include
android:id="@+id/edittextEmail"
layout="@layout/edittext_email_base_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_xxxxlarge"
/>