Last active
December 3, 2015 15:49
-
-
Save t-kashima/8be3ee927fedd8b9ad3d to your computer and use it in GitHub Desktop.
RxJavaで入力の状態によって条件を分ける
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ボタンを押した時に入力が空の時は何もしないで | |
* 入力はあるが20文字より多い時はエラーを表示する | |
*/ | |
mButton.setOnClickListener(v -> | |
Observable.just(mEditText.getText().toString()) | |
.filter(text -> !text.isEmpty()) | |
.filter(text -> { | |
if (20 < text.length()) { | |
throw new IllegalStateException("Invalid your text length."); | |
} | |
return true; | |
}).subscribe(text -> | |
Log.d("MainActivity", "OK, Your text is " + text) | |
, error -> | |
Log.e("MainActivity", "NG, " + error.getMessage()) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment