RxJava and Rxandroid II

Source: Internet
Author: User

A friend who doesn't know about Rx can read my first blog post RxJava and Rxandroid , which is a basic introduction to RxJava.

1. Merge operator, merging observed objects
1  Packageapp.com.myapplication;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 6 Importjava.util.ArrayList;7 Importjava.util.List;8 9 ImportRx. Observable;Ten ImportRx.functions.Action1; One  A  Public classMergeactivityextendsappcompatactivity { -  - @Override the     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_merge); -  +List<string> List1 =NewArraylist<>() ; -List<string> List2 =NewArraylist<>() ; +  AList1.add ("1" ) ; atList1.add ("2" ) ; -List1.add ("3" ) ; -  -List2.add ("a" ) ; -List2.add ("B" ) ; -List2.add ("C" ) ; in  -Observable Observable1 =Observable.from (list1); toObservable Observable2 =Observable.from (list2); +  -         //merge data sends all OBSERVABLE2 data first, and then sends all OBSERVABLE1 data theObservable Observable =Observable.merge (Observable2, observable1); *  $Observable.subscribe (NewAction1 () {Panax Notoginseng @Override -              Public voidCall (Object o) { theSystem.out.println ("rx--" +o); +             } A         }) ; the  +     } -}

Run results

RxJava and Rxandroid II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.