Created
September 5, 2017 02:12
-
-
Save maxost/c6b1bf9f42868d25808a22fcad17abd3 to your computer and use it in GitHub Desktop.
Kotlin: editText Observable extension in Android
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
fun EditText.toObservable(): Observable<String> { | |
return Observable.create({ | |
val watcher = object : TextWatcher { | |
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
scream("aaa" + p0.toString()) | |
it.onNext(p0.toString()) | |
} | |
override fun afterTextChanged(p0: Editable?) { } | |
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { } | |
} | |
this.addTextChangedListener(watcher) | |
it.setCancellable { this.removeTextChangedListener(watcher) } | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment