EditText: handle text changes

If you want to listen for text changes at a editText you will probably use the onKeyListener listener. That’s ok if you are using the hardware keyboard, but how will you detect the keydown event from a software keyboard?

addTextChangedListener is your new onKeyListener

		searchBox = (EditText) findViewById(R.id.searchBox);
		searchBox.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				//onTextChanged
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				//beforeTextChanged

			}

			@Override
			public void afterTextChanged(Editable s) {
				//afterTextChanged
				String typedText = s.toString();
			}
		});
Share