花了我一天要弄清楚,使用安口的解析器一個光標映射到一個對象是問題:
fun <T: Any> Cursor.parseList(parser: RowParser<T>): List<T> = AnkoInternals.useCursor(this) {
val list = ArrayList<T>(count)
moveToFirst()
while (!isAfterLast) {
list.add(parser.parseRow(readColumnsArray(this)))
moveToNext()
}
return list
}
長話短說:當用戶點擊Recyclerview項目,我會使用光標從適配器,並將其移動到當前位置,然後我試圖將光標映射到我的模型使用:
val cursor = mAdapter?.cursor
cursor?.moveToPosition(it)
Observable.defer {
val uploadingItem = cursor?.parseList(UploadParser())
if (uploadingItem == null) {
Exceptions.propagate(IllegalArgumentException())
}
Observable.just(UploadInfoArgs.parseUploading(uploadingItem?.get(it)!!))
}.subscribeOn(Schedulers.immediate()).observeOn(AndroidSchedulers.mainThread())
哪行cursor?.parseList(UploadParser())是我的列表在更改後不會更新的問題!