I have a custom view that wraps an edit text.
I want the the observe the changes of this edit text at the class that uses this Custom View, using Data Binding.
How can I expose the input string of the edit text to the other classes that use the custom view?
Is two way data binding the only way?
In other XML:
<MyCustomView
android:id="@+id/password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:password="@={controller.password}"
app:isPasswordValid="@={controller.isValid}"/>
The layout of the custom view (Linear Layout):
<merge>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/security_code_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/email_text_view">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/security_code_edit_text"
android:background="@drawable/edittext_background"
android:inputType="textPassword"
android:text="@={view.pass}"
app:onSubmit="@{() -> view.onKeyboardActionDoneClicked()}" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/textfield_error_invalid_password_length"
app:visibleOrGone="@{view.showInvalidPasswordText}" />
</merge>
from Android Data Binding - Observe edit text's value that is wrapped in custom view
No comments:
Post a Comment