RxJava and RxAndroid 2, rxjavarxandroid

Source: Internet
Author: User

RxJava and RxAndroid 2, rxjavarxandroid

Friends who do not know about Rx can read my first blog posts RxJava and RxAndroid, which is a basic introduction to Rxjava.

 

1. merge operator, which combines observed objects
1 package app.com. myapplication; 2 3 import android. support. v7.app. appCompatActivity; 4 import android. OS. bundle; 5 6 import java. util. arrayList; 7 import java. util. list; 8 9 import rx. observable; 10 import rx. functions. action1; 11 12 public class MergeActivity extends AppCompatActivity {13 14 @ Override15 protected void onCreate (Bundle savedInstanceState) {16 super. onCreate (savedInstanceState); 17 setContentView (R. layout. activity_merge); 18 19 List <String> list1 = new ArrayList <> (); 20 List <String> list2 = new ArrayList <> (); 21 22 list1.add ("1"); 23 list1.add ("2"); 24 list1.add ("3"); 25 26 list2.add (""); 27 list2.add ("B"); 28 list2.add ("c"); 29 30 Observable observable1 = Observable. from (list1); 31 Observable observable2 = Observable. from (list2); 32 33 // the merged data first sends all data of observable2, and then sends all data of observable1 34 Observable observable Observable = Observable. merge (observable2, observable1); 35 36 observable. subscribe (new Action1 () {37 @ Override38 public void call (Object o) {39 System. out. println ("rx --" + o); 40} 41}); 42 43} 44}

Running result

 

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.