Snippets

サトミツジムラ RxJava Hello, World!

Created by サトミツジムラ
package jp.gr.java_conf.qkuronekop.rxsample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import rx.Observable;

/**
 * Created by qkuronekop on 2016/05/26.
 */

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        String[] hellos = {"Hell,", " World!"};

        Observable.from(hellos)
                .reduce((p, c) -> {
                    return p + c;
                })
                .subscribe(s -> {
            ((TextView) findViewById(R.id.second_text_view)).setText(s.toString());
        });

    }
}

Comments (0)