我有以下的ViewModel类:
class PersonViewModel(
context: Application,
private val dataSource: MoviesRemoteDataSource)
: AndroidViewModel(context) {
internal val compositeDisposable = CompositeDisposable()
val person: ObservableField<Person>()
private val isVisible = ObservableBoolean(false)
fun showPerson(personId: String) {
val personSubscription = dataSource.getPerson(personId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ person ->
isVisible.set(true)
this.person.set(person)
}
) { throwable -> Timber.e(throwable) }
compositeDisposable.add(personSubscription)
}
}
这是Person类:
class Person(
@SerializedName("birthday")
var birthDay: String?,
@SerializedName("deathday")
var deathDay: String?,
var id: Int,
@SerializedName("also_known_as")
var alsoKnowAs: List<String>,
var biography: String,
@SerializedName("place_of_birth")
var placeOfBirth: String?)
在ViewModel中,这一行显示了一个错误:
val person: ObservableField<Person>()
它的意思是:需要属性的getter或setter
非常感谢您的帮助。