Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the TextWatcher class in Android?

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.

like image 268
Android developer Avatar asked Dec 17 '11 07:12

Android developer


People also ask

What is the use of TextWatcher in Android?

EditText uses TextWatcher interface to watch change made over EditText. For doing this, EditText calls the addTextChangedListener() method.

In which condition is TextWatcher used?

The TextWatcher interface can be used for listening in for changes in text in an EditText.

What is TextWatcher Android studio?

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 .

How do I use addTextChangedListener?

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.


1 Answers

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     } }); 
like image 172
Dinesh Prajapati Avatar answered Oct 11 '22 00:10

Dinesh Prajapati