为了使用RxJava实现在ImageView中每隔指定时间加载一张系统图片的效果,
1 2 3 4 5 6 |
|
在getUri()中返回了一个ArrayList<Uri>对象,然后每次发射一个uri到订阅者中,怎么让这个发射过程延迟调用。
使用timer操作符出现了以下错误:Unknown type class java.lang.Long. You must provide a Model of a type for which there is a registered ModelLoader, if you are using a custom model, you must first call Glide#register with a ModelLoaderFactory for your custom model class
天蓬老师2017-04-17 18:02:49
你這個錯誤貌似你Glide引起的,跟Timer沒什麼關係把!
timer是延時發射函數,只執行一次。想要定時發送數據,試試interval函數:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
迷茫2017-04-17 18:02:49
對於定時任務,必然是從interval開始,不要老是想著從資料開始
1 2 3 4 5 6 |
|
樓主的錯誤在於,timer是靜態方法,前面的from(getUri())根本沒起到作用,發送出來的不是圖片地址,而是循環次數,類型是Long,丟給Glide後類型出錯。
ringa_lee2017-04-17 18:02:49
from完在走一個delay即可,具體api如下http://reactivex.io/RxJava/javadoc/rx/Observable.html#delay(rx.functions.Func1)