Reputation: 614
<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 = "registrationViewModel"
type="com.android.freecommunity.ui.auth.AuthViewModel"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:context=".ui.auth.Register">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="352dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/intro_background" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="@drawable/round_layout_container"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edit_text"
android:drawableLeft="@drawable/user"
android:drawablePadding="16dp"
android:ems="10"
android:hint="Fullname"
android:text="@={registrationViewModel.fullName}"
android:inputType="phone"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<EditText
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edit_text"
android:drawableLeft="@drawable/email"
android:drawablePadding="16dp"
android:ems="10"
android:hint="Email Address"
android:text="@={registrationViewModel.email}"
android:inputType="textEmailAddress"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edge_button"
android:text="REGISTER"
android:onClick="@={(view)-> registrationViewModel.onRegisterButtonClicked(view)}"
android:textColor="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner2" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Already a member"
android:textColor="@color/not_a_member"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Login"
android:onClick="@{registrationViewModel::onLogin}"
android:textColor="@color/not_a_member"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Forget Password ?"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_begin="81dp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationY="-10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/logo_holder"
tools:layout_editor_absoluteY="-22dp" />
<EditText
android:id="@+id/editText3"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edit_text"
android:drawableLeft="@drawable/phone"
android:drawablePadding="16dp"
android:ems="10"
android:hint="Phone"
android:text="@={registrationViewModel.phoneNumber}"
android:inputType="phone"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText2" />
<EditText
android:id="@+id/editText4"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edit_text"
android:drawableLeft="@drawable/calendar"
android:drawablePadding="16dp"
android:ems="10"
android:hint="DOB"
android:text="@={registrationViewModel.date_of_birth}"
android:inputType="date"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />
<EditText
android:id="@+id/editText5"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/round_edit_text"
android:drawableLeft="@drawable/address"
android:drawablePadding="16dp"
android:ems="10"
android:hint="Home Address"
android:text="@={registrationViewModel.address}"
android:inputType="textPersonName"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText4" />
<Spinner
android:id="@+id/spinner"
android:layout_width="345dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/round_edit_text"
android:drawSelectorOnTop="true"
android:entries="@array/work_category_array"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText5" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:drawSelectorOnTop="true"
android:entries="@array/daily_payment_plan"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Thats my xml
fun onRegisterButtonClicked(view: View){
authListener?.onStarted()
if (fullName.isNullOrEmpty()){
authListener?.onFailure("FullName is required")
return
}
if (email.isNullOrEmpty()){
authListener?.onFailure("Email is required")
return
}
if (password.isNullOrEmpty()){
authListener?.onFailure("Password is required")
return
}
This is where im trying to use the function inside my view model, i've tried all other way to do the onclick in my xml, but i keep getting errors. [please ignore]
This is where im trying to use the function inside my view model, i've tried all other way to do the onclick in my xml, but i keep getting errors. This is where im trying to use the function inside my view model, i've tried all other way to do the onclick in my xml, but i keep getting errors.
Upvotes: 2
Views: 7145
Reputation: 213
You must import View first. Add the following to the top of your layout:
<data>
<import type="android.view.View"/>
</data>
More details :https://developer.android.com/topic/libraries/data-binding/expressions#imports
Upvotes: 20
Reputation: 40898
So since you didn't provide the error log you get, I will try to add potential cause as mentioned in the question title
Data binding could not find identifier “view”
In your layout you need to remove view
from the button click callback and the equal sign is useless, so replace below
<Button
android:id="@+id/button"
android:onClick="@={(view)-> registrationViewModel.onRegisterButtonClicked(view)}" />
with
<Button
android:id="@+id/button"
android:onClick="@{()-> registrationViewModel.onRegisterButtonClicked()}" />
or you also use
<Button
android:id="@+id/button"
android:onClick="@{registrationViewModel::onRegisterButtonClicked}" />
I omitted other attributes, so keep them unchanged.
Upvotes: 0