作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试使用 RxAndroid
button.setOnClickListener(view -> restApiFactory.testService().getListTest(7)
.subscribeOn(Schedulers.io())
.subscribe(new Observer<List<Test>>() {
但是我得到了以下错误:
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
我还没有使用过AndroidSchedulers.mainThread()
最佳答案
您需要从主线程操作UI
所以为了做到这一点您需要告诉 rxandroid 通知主线程上的更改所以使用
button.setOnClickListener(view -> restApiFactory.testService().getListTest(7)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
// ^^^^^^^^^^
.subscribe(new Observer<List<Test>>() {
要获得它,您需要有一个依赖项
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
并且您当前的依赖项用于进行改造 retuns rxAndroid
类型响应。
关于android - 只有创建 View 层次结构的原始线程才能触及它的 View 。 Rx安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47204264/
我正在尝试创建一个 React 组件来抽象化为我的表单创建一个输入组。所有输入都具有相同的布局 - 一个标签,下面是输入,如果存在错误/信息文本,它们将显示在输入下。 以前我处理自己的表单状态/处理程
我正在尝试将子 shell 的输出行读取到数组中,但我不愿意设置 IFS,因为它是全局的。我不希望脚本的一部分影响后面的部分,因为那是不好的做法,我拒绝这样做。在命令后恢复 IFS 不是一个选项,因为
我是一名优秀的程序员,十分优秀!