1,kotlinx.android.synthetic遇到的坑
循环addView(itemView) adapter中都只正确初始化了第一个item, 不用这个就正常
当从后台返回前台时当从后台返回前台时Kotlin莫名会闪退
override fun setLayout() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
kotlin.NotImplementedError: An operation is not implemented: not implemented
2,Kotlin与Butteknife兼容性
用kotterknife.bindView代替
https://github.com/JakeWharton/kotterknife
3,
private inner class SearchViewTextListener(var emitter: ObservableEmitter<String>) : SearchView.OnQueryTextListener {
override fun onQueryTextChange(newText: String?): Boolean {
newText?.let { emitter.onNext(it) }
return false
}
override fun onQueryTextSubmit(query: String?): Boolean {
query?.let { emitter.onNext(it) }
return false
}
}
Observable.create(ObservableOnSubscribe<String> { e ->
val listener = SearchViewTextListener(e)
searchView.setOnQueryTextListener(listener)
})
.debounce(300, TimeUnit.MILLISECONDS)
.filter { t -> t.isNotEmpty() }
.switchMap { query ->
Observable.create(ObservableOnSubscribe<EventPickSearchResult> { observableEmitter ->
val requestSearch = requestSearch(query)
if (requestSearch != null) {
observableEmitter.onNext(requestSearch)
}
observableEmitter.onComplete()
})
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : DisposableObserver<EventPickSearchResult>() {
override fun onComplete() {
UIKeyboardHelper.hideKeyboard(searchView)
searchResultAdapter.setNewData(null)
}
override fun onError(e: Throwable) {
}
override fun onNext(result: EventPickSearchResult) {
if (!TextUtils.isEmpty(searchView.query)) {
searchResultList.visibility = View.VISIBLE
refreshLayout.visibility = View.GONE
updateSearchList(result)
} else {
searchResultList.visibility = View.GONE
refreshLayout.visibility = View.VISIBLE
plateid = 0
requestNetData(plateid)
}
}
})
}
网友评论