我是RxJava和RxAndroid的新手。我正在尝试在数组中搜索关键字,如果找到任何数据,我正在使用适配器在列表视图中尝试更新。但应用程序受到了打击,而不是电影。你能不能帮助解决这个问题。我附上了我试过的......
提前致谢
val dataArray = ArrayList<CisData>();
var cisDataAdaptor : CisDataAdaptor ;
var isFirst = true
Observable.create(ObservableOnSubscribe<CisData> { e ->
var word = "Test"
val search = ".*$word.*"
val regex = Pattern.compile(search)
for (index in resources.getStringArray(R.array.list).indices) {
if (regex.matcher(resources.getStringArray(R.array.list).get(index)).find()) {
e.onNext(CisData(resources.getStringArray(R.array.list_of_kural).get(index), (index + 1).toString()))
}
}
e.onComplete()
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
object : DisposableObserver<CisData>() {
override fun onNext(response: CisData) {
dataArray.add(response)
if (isFirst) {
cisDataAdaptor = CisDataAdaptor(context, dataArray)
list_view!!.adapter = cisDataAdaptor
isFirst = false
} else {
cisDataAdaptor!!.notifyDataSetChanged()
}
}
override fun onError(e: Throwable) {
}
override fun onComplete() {
}
})