Amos Fox
Amos Fox

Reputation: 310

Edittext aftertextchange triggers multiple times when text changed programmatically

afterTextChanged is triggered for each character of the string if I change the contents of the EditText programmatically. Shouldn't editText.setText("abc") just trigger the listener once instead of 3 times?

Upvotes: 0

Views: 200

Answers (1)

Mohamed Hussein
Mohamed Hussein

Reputation: 91

to detect if the user change the text or changed programmatically you can use the setTag() function for ex:

eddittext.setTag( "programmatically" );
eddittext.setText( "your text" );
eddittext.setTag(null);

//-----------------------------
@Override public void afterTextChanged(Editable s) {
if( eddittext.getTag() == null )             
      // Value changed by user
else
      // changed programmatically
}

Upvotes: 2

Related Questions