Newer
Older
DevAndroid / app / src / main / res / layout / fragment_main.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">

    <data>

        <variable
            name="mainViewModel"
            type="keijumt.devandroid.viewmodel.MainViewModel" />
    </data>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <EditText
            android:id="@+id/edit_postal_code"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/input_postal_code"
            android:inputType="number"
            android:text="@={mainViewModel.postalCode}"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/btn_search_postalcode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="@{mainViewModel.postalCode.length == 7 ? true : false}"
            android:onClick="@{() -> mainViewModel.search()}"
            android:text="@string/search"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/edit_postal_code" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{mainViewModel.address}"
            app:layout_constraintTop_toBottomOf="@id/btn_search_postalcode" />


    </android.support.constraint.ConstraintLayout>
</layout>