Can anyone tell me how to mask the substring in EditText
or how to change EditText
substring input to password type or replace by another character like this 123xxxxxxxxx3455
String contents = et1.getText().toString(); et1.setText(contents.replace.substring(0, contents.length()-2),"*");
Please, tell me how I can use the TextWatcher
method in Android.
EditText uses TextWatcher interface to watch change made over EditText. For doing this, EditText calls the addTextChangedListener() method.
The TextWatcher interface can be used for listening in for changes in text in an EditText.
Public methodsThis method is called to notify you that, within s , the count characters beginning at start are about to be replaced by new text with length after . This method is called to notify you that, within s , the count characters beginning at start have just replaced old text that had length before .
You should create a Listener class like so, Just modify the parameters in the constructor to accept the EditText ID you want to add a listener to. mobileNumber2. addTextChangedListener(new addListenerOnTextChange(this, mobileNumber2)); Again modify the parameters as needed.
For use of the TextWatcher
...
et1.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With