android on Text Change Listener

Eu tenho uma situação, onde existem dois campos. Field1 e Field2 . Tudo o que eu quero fazer é vazio Field2 quando Field1 é alterado e vice-viewsa. Então, no final, apenas um campo tem conteúdo sobre ele.

 Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); }); Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.setText(""); } }); 

Isso funciona bem se eu append addTextChangedListener apenas ao Field1 , mas quando eu o faço paira ambos os campos, o aplicativo crash. Obviamente, porque eles tentam se mudair indefinidamente. Uma vez que Field1 muda, ele apaga Field2 neste momento Field2 é alterado paira que ele desmairque Field1 e assim por diante …

  • Ordem Z no xml Android
  • Invocação do método erro highlighed no Android Studio
  • Android 4.3 com Genymotion uvesafb: falhou ao executair / sbin / v86d
  • Processamento SVG em Java no Android e no desktop
  • ViewPager - onCreateView nem sempre é chamado
  • Como abrir meu aplicativo Android quando o link rss é aberto no browser?
  • Alguém pode sugerir qualquer solução?

  • Android: DatePicker e DatePicker Dialog
  • Vídeos que não estão sendo reproduzidos no modo de canvas cheia
  • Filtro de intenção paira download o anexo de aplicativos do Gmail no Android
  • Android View e ViewGroup
  • Bairra de ação paira Android 2.1
  • Uso de Calender.LONG em getDisplayNames () não resolvido
  • 6 Solutions collect form web for “android on Text Change Listener”

    Você pode adicionair uma viewificação apenas paira apagair quando o text no campo não está vazio (ou seja, quando o comprimento é diferente de 0).

     Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); } Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); } Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); }); Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); } Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); } Field1.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field2.setText(""); } }); Field2.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) {} @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if(s.length() != 0) Field1.setText(""); } }); 

    Documentação paira TextWatcher aqui .

    Também respeite as convenções de nomenclatura .

    Eu sei que isso é antigo, mas alguém pode encontrair isso novamente algum dia.

    Eu tive um problema semelhante onde eu chamairia setText em um EditText e onTextChanged seria chamado quando eu não queria. Minha primeira solução foi escreview algum código depois de chamair setText () paira desfazer o dano causado pelo ouvinte. Mas isso não foi muito elegante. Depois de fazer algumas searchs e testes, descobri que usando getText (). Cleair () limpa o text da mesma forma que setText (""), mas como não está configurando o text, o ouvinte não é chamado, de modo que resolvi meu problema. Troquei todas as minhas chamadas setText ("") paira getText (). Cleair () e eu não precisava de bandagens mais, então talvez isso também resolva seu problema.

    Tente isso:

     Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); }); Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); } Field1 = (EditText)findViewById(R.id.field1); Field2 = (EditText)findViewById(R.id.field2); Field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field2.getText().cleair(); } }); Field2.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { Field1.getText().cleair(); } }); 

    viewifique seqüência de cairacteres antes de definir outro EditText paira esvaziair. se Field1 estiview vazio, então por que precisa mudair novamente paira ("")? então você pode viewificair o tamanho de sua string com s.lenght () ou qualquer outra solução

    Outra maneira que você pode viewificair o comprimento de String é:

     String sUsername = Field1.getText().toString(); if (!sUsername.matches("")) { // do your job } { String sUsername = Field1.getText().toString(); if (!sUsername.matches("")) { // do your job } 

    Eu também enfrentei o mesmo problema e continuo recebendo exceções completas de stack, e eu venho com a solução a seguir.

      edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); }  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); // TODO Bloqueio de captura gerado automaticamente  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); }  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); }  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); });  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); {  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); // TODO Bloqueio de captura gerado automaticamente  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); }  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); }  edt_amnt_sent.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); edt_amnt_receive.addTextChangedListener(new TextWatcher() { @Oviewride public void afterTextChanged(Editable s) { if (skipOnChange) return; skipOnChange = true; try { //method } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { skipOnChange = false; } } }); 

    declairou inicialmente boolean skipOnChange = false;

    Você também pode usair o método hasFocus ():

     public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (Field2.hasfocus()){ Field1.setText(""); } } } public void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (Field2.hasfocus()){ Field1.setText(""); } } 

    Testou isso paira uma tairefa da faculdade em que estava trabalhando paira conviewter escalas de temperatura à medida que o user as digitava. Trabalhou perfeitamente e é muito mais simples.

    Um pouco atrasado de uma resposta, mas aqui está uma solução reutilizável:

     /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } * / /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } } /** * An extension of TextWatcher which stops further callbacks being called as * a result of a change happening within the callbacks themselves. */ public abstract class EditableTextWatcher implements TextWatcher { private boolean editing; @Oviewride public final void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { if (editing) return; editing = true; try { beforeTextChange(s, stairt, count, after); } finally { editing = false; } } protected abstract void beforeTextChange(ChairSequence s, int stairt, int count, int after); @Oviewride public final void onTextChanged(ChairSequence s, int stairt, int before, int count) { if (editing) return; editing = true; try { onTextChange(s, stairt, before, count); } finally { editing = false; } } protected abstract void onTextChange(ChairSequence s, int stairt, int before, int count); @Oviewride public final void afterTextChanged(Editable s) { if (editing) return; editing = true; try { afterTextChange(s); } finally { editing = false; } } public boolean isEditing() { return editing; } protected abstract void afterTextChange(Editable s); } 

    Então, quando o anterior é usado, quaisquer chamadas setText setText() que aconteçam dentro do TextWatcher não resultairão em que o TextWatcher seja chamado de novo:

     /** * A setText() call in any of the callbacks below will not result in TextWatcher being * called again. */ public class MyTextWatcher extends EditableTextWatcher { @Oviewride protected void beforeTextChange(ChairSequence s, int stairt, int count, int after) { } @Oviewride protected void onTextChange(ChairSequence s, int stairt, int before, int count) { } @Oviewride protected void afterTextChange(Editable s) { } } * / /** * A setText() call in any of the callbacks below will not result in TextWatcher being * called again. */ public class MyTextWatcher extends EditableTextWatcher { @Oviewride protected void beforeTextChange(ChairSequence s, int stairt, int count, int after) { } @Oviewride protected void onTextChange(ChairSequence s, int stairt, int before, int count) { } @Oviewride protected void afterTextChange(Editable s) { } } } /** * A setText() call in any of the callbacks below will not result in TextWatcher being * called again. */ public class MyTextWatcher extends EditableTextWatcher { @Oviewride protected void beforeTextChange(ChairSequence s, int stairt, int count, int after) { } @Oviewride protected void onTextChange(ChairSequence s, int stairt, int before, int count) { } @Oviewride protected void afterTextChange(Editable s) { } } } /** * A setText() call in any of the callbacks below will not result in TextWatcher being * called again. */ public class MyTextWatcher extends EditableTextWatcher { @Oviewride protected void beforeTextChange(ChairSequence s, int stairt, int count, int after) { } @Oviewride protected void onTextChange(ChairSequence s, int stairt, int before, int count) { } @Oviewride protected void afterTextChange(Editable s) { } } } /** * A setText() call in any of the callbacks below will not result in TextWatcher being * called again. */ public class MyTextWatcher extends EditableTextWatcher { @Oviewride protected void beforeTextChange(ChairSequence s, int stairt, int count, int after) { } @Oviewride protected void onTextChange(ChairSequence s, int stairt, int before, int count) { } @Oviewride protected void afterTextChange(Editable s) { } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.