【发布时间】:2017-11-09 14:23:51
【问题描述】:
我尝试使用 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应该从主线程更新,没有逃脱的地方 -
我知道。但我不知道如何告诉观察者主线程
-
在
.subscribe(new Observer<List<Te...之前添加这个..observeOn(AndroidSchedulers.mainThread()) -
我在我的问题中写道 - 我没有 AndroidSchedulers 类
-
我还说,没有逃脱,你没有
AndroidSchedulers class是什么意思?您需要具体说明问题和限制
标签: android retrofit2 rx-android