草庐IT

observables

全部标签

android - 从 LiveData.observe() 添加项目到适配器的最佳实践

我有DAO方法返回LiveData>:LiveData>listLiveData=categoryDao.getAll();之后我需要将此数据设置到我的适配器:listLiveData.observe(this,categories->{if(categories==null||categories.isEmpty()){price.setVisibility(View.VISIBLE);recyclerView.setVisibility(View.INVISIBLE);}else{categoryAdapter=newCategoryAdapter(categories);cate

java - Observable merge() 检测哪个 observable 被触发

我正在使用值列表创建一个Observable列表,每个值都是一个自定义Observable。我使用合并运行它们,但我无法检测到哪个触发onNext()或onError()像下面的代码:List>observables=newArrayList();for(Stringparam:paramsList){ObservableobjObservable=MyRestClient.get().doHttpRequest(param);observables.add(fileUploadObservable);}ObservablecombinedObservables=Observable.

android - 在 rxJava 中压缩超过 9 个 Observable

遇到需要做10-12个小的并行查询并合并结果的情况。但是如果有一个zip方法可以让你组合最多9个Observables,那么我不明白如何做更多。我尝试使用zip方法publicstaticObservablezip(Iterable>sources,Functionzipper)但是却报错了java.lang.ClassCastException:java.util.ArrayListcannotbecasttoio.reactivex.ObservableSource尝试看起来像这样Listlist=newArrayList();list.add(orderRepository.ge

首次更新后 Android LiveData Observer 未激活

我正在像这样使用Kotlin尝试架构组件的实时数据的基本实现:classMarketFragment:LifecycleFragment(){......overridefunonActivityCreated(savedInstanceState:Bundle?){super.onActivityCreated(savedInstanceState)viewModel=ViewModelProviders.of(this).get(MarketViewModel::class.java)viewModel.book?.observe(this,Observer{book->//upd

android - Bindable 必须在 Observable 类的成员上

我是数据绑定(bind)的新手,这是我的代码,但我在构建时遇到了这个错误classDatabindingViewModel:ViewModel(){valcurrentFruitName:LiveDataget()=FakeRepository.currentNamefunchangeNameOnClick()=FakeRepository.changeRandomFoodName()//twowayLiveData@BindablevaleditTextContext=MutableLiveData()privateval_displayEditTexfContent=Mutable

使用Redux-Observable处理Apollo-Client的错误

我正在使用Apollo-Client和Redux-Observable进行突变,到目前为止,这是我的代码:exportconstlanguageTimeZoneEpic=(action$)=>{returnaction$.ofType('PING').flatMap(action=>client.mutate({mutation:languageTimeZoneIdMutation,variables:{id:action.id,defaultLanguage:action.selected_language,defaultTimeZoneId:action.selected_timeZone

java - "No Instance of type variable R exist so that Observable conforms to Observable"更新到 RxJava2 时出错

我正在尝试使用retrofit和rxJava调用API。下面的代码似乎在使用RxJava1时运行良好,但是一旦我更新到RxJava2我就收到了这个错误:错误:NoInstanceoftypevariableRexistsothatObservableconformstoObservableAPIObservable>>getList(@Query("key")Stringkey);Api请求在这里完成,这是我在.map运算符中得到这个错误的地方Observablecache=providers.getList().map(newHttpRsltFunc>());结果类模型:privat

android - 基于 Observable 的 API 和取消订阅问题

我正在尝试使用Rx-Java创建一个用于在Android上进行位置跟踪的类。我仍然无法弄清楚的是如何正确处理我的Observable的生命周期。我想要的是一个Observable,它在第一次订阅发生时开始跟踪位置,并在最后一个订阅被丢弃时停止位置跟踪。到目前为止,我取得的成就是:publicclassLocationObservableimplementsGooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener{pri

android - 如何在 onActivityResult 方法收到 Intent 结果后设置 Observer 以更新抽屉导航

在我的应用程序中,我想在他登录后使用用户名的昵称和电子邮件更新抽屉导航。从我的MainActivity我正在使用startActivityForResult(intent,PICK_ACCOUNT_REQUEST);方法启动一个LoginActivity让用户注册或登录。LoginActivity返回Intentdata结果(他的NAME和EMAIL)返回给后MainActivity,方法onActivityResult()被调用,我尝试更新类的全局变量NAME和EMAIL新收到的数据,没有成功:每次注册或登录后,这两个字段从未显示在抽屉导航中。这是我的代码:在MainActivity

android - RxAndroid,在 onDestroy() Activity 中停止计时器/observable.interval

我在我的应用程序中使用RxAndroid来处理计时器任务。用Observable.interval()来做。一切正常,但我需要在Activity的onDestroy()中停止计时器。我真的不知道怎么做。谁能帮帮我?这是我正在使用的代码:Observable.interval(0,10,TimeUnit.SECONDS).flatMap(n->mObservableNewChat).doOnError(i->showNoInternetConnection()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainTh