I am using data binding, I am trying to create a class with the values when the user fills up multiple edit texts, also with some validations.
the class is something like
data class Person(
var name: String,
var age: Int,
var email: String
)
The view model variable,
val person: MutableLiveData<Person> by lazy { MutableLiveData<Person>()}
The template
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="@{viewModel.person.name}" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="@{viewModel.person.age}" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="@{viewModel.person.email}" />
with the click on button, I am trying to print out the object,
binding.savebtn.setOnClickListener {
Log.d("debug", "${viewModel.person.value}:")
}
and it prints out D/debug: null:
I am trying to create a room entity after validation. How can I make this work?