android - rxjava buffer操作符使用
問題描述
rxjava中的操作符能夠buffer功能之一是能夠收集輸出一個數組
ArrayList<LatLng> latLngs=......;Observable.from(latLngs).map(new Func1<LatLng, OverlayOptions>() { @Override public OverlayOptions call(LatLng latLng) {Bitmap bimap;if (url.endsWith('svg')) { bimap = LoadImage.getSvgBitmap(context, url); bimap = ScreenUtils.getScaleBitmapSvg(context, bimap);} else { bimap = LoadImage.getBitmap(context, url); bimap = ScreenUtils.getScaleBitmap(context, bimap);}BitmapDescriptor bitDes = BitmapDescriptorFactory.fromBitmap(bimap);OverlayOptions option = new MarkerOptions().position(latLng).icon(bitDes);return option; }}).buffer(latLngs.size())//一次性全部集齊.subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()).subscribe(new Action1<List<OverlayOptions>>() { @Override public void call(List<OverlayOptions> overlayOptionses) {baiduMap.addOverlays(overlayOptionses);//全部添加到地圖上 }});
但是前提是能夠知道最終輸出數組的長度,但是我如果添加一個篩選操作,就不知道最終得到的數組長度了,但是我還是想直接得到一個數組應該怎樣做呀
問題解答
回答1:根據樓主的描述,toList()操作符可能更滿足你的需求。
相關文章:
1. javascript - 我的站點貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?2. dockerfile - 為什么docker容器啟動不了?3. javascript - webapp業務流程基本一致,多套主題(樣式基本不一樣,交互稍有偏差)管理,并且有不斷有新增主題,該如何設計組件化架構?4. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應5. 新手 - Python 爬蟲 問題 求助6. macos - mac下docker如何設置代理7. javascript - 從mysql獲取json數據,前端怎么處理轉換解析json類型8. angular.js - ng-grid 和tabset一起用時,grid width默認特別小9. mysql - AttributeError: ’module’ object has no attribute ’MatchType’10. javascript - 學習網頁開發,關于head區域一段腳本的疑惑
