Skip to content

Instantly share code, notes, and snippets.

@n8ebel
Created August 13, 2015 22:13
Show Gist options
  • Save n8ebel/62a2a96a5fb4c0ec07c2 to your computer and use it in GitHub Desktop.
Save n8ebel/62a2a96a5fb4c0ec07c2 to your computer and use it in GitHub Desktop.

Simple illustration of responding to text changed events on an EditText.

/*
 *  RxJava
 */
RxTextView.textChangeEvents(mEditText)
    .subscribe(event -> mResultTextView.setText(event.text()));

/*
 * Standard
 */
mEditText.addTextChangedListener(new TextWatcher() {
  @Override
  public void beforeTextChanged(CharSequence s, int start, int count, int after) {

  }

  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count) {
    mResultTextView.setText(s);
  }

  @Override
  public void afterTextChanged(Editable s) {

  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment