package jackall.devrealm.viewmodel import android.arch.lifecycle.ViewModel import android.databinding.ObservableField import jackall.devrealm.vo.Person /** * Created by matsumoto_k on 2017/11/08. */ class ItemViewModel(person: Person) : ViewModel() { val firstName = ObservableField<String>(person.firstName) val lastName = ObservableField<String>(person.lastName) val age = ObservableField<String>(person.age.toString()) init { person.addChangeListener<Person> { person -> if (person.isValid) { firstName.set(person.firstName) lastName.set(person.lastName) age.set(person.age.toString()) } } } }