Android响应式编程开发RxAndroid(6):range
range的参数意义,range(x,count),从x起,发射count个数据,例如代码:
package zhangphil.app;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import java.util.UUID;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
public class MainActivity extends Activity {
private final String TAG = String.valueOf(UUID.randomUUID());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Observable.range(1, 5).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
Log.d(TAG, String.valueOf(integer));
}
});
}
}
运行结果输出:
03-20 12:24:24.519 12354-12354/zhangphil.app D/30f76924-396e-4722-b118-e7c8a17e9cdc: 1
03-20 12:24:24.519 12354-12354/zhangphil.app D/30f76924-396e-4722-b118-e7c8a17e9cdc: 2
03-20 12:24:24.519 12354-12354/zhangphil.app D/30f76924-396e-4722-b118-e7c8a17e9cdc: 3
03-20 12:24:24.519 12354-12354/zhangphil.app D/30f76924-396e-4722-b118-e7c8a17e9cdc: 4
03-20 12:24:24.519 12354-12354/zhangphil.app D/30f76924-396e-4722-b118-e7c8a17e9cdc: 5
附录:
1,《Android响应式编程RxAndroid(1):简单例程》链接地址:http://blog.csdn.net/zhangphil/article/details/58593782
2,《Android响应式编程开发RxAndroid(2):简单例程的Android改造 》链接地址:http://blog.csdn.net/zhangphil/article/details/58597372
3,《Android响应式编程开发RxAndroid(3):map》链接地址:http://blog.csdn.net/zhangphil/article/details/59130641
4,《Android响应式编程开发RxAndroid(4):flatMap》链接地址:http://blog.csdn.net/zhangphil/article/details/59483465
5,《Android响应式编程开发RxAndroid(5):RxJava 2.0的Consumer》链接地址:http://blog.csdn.net/zhangphil/article/details/59493604