Newer
Older
DevRealm / app / src / main / java / jackall / devrealm / viewmodel / ItemViewModel.kt
MatsumotoKeiju on 8 Nov 2017 649 bytes [add] Custom RecyclerView Adapter
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 ->
            firstName.set(person.firstName)
            lastName.set(person.lastName)
            age.set(person.age.toString())
        }
    }
}