title: onTextChanged event in Android
body: <p>My problem is little tangled, i have to EditText boxes. Now, when i typing something on first EditText then its shows on second EditText. And as vice versa while typing on second EditText it sets on first EditText. But it gives some error on setText of any one of EditText. Below is my code,</p>
  
  <pre><code>Boolean flag,flag2;
  txt_editText_1.addTextChangedListener(new TextWatcher() {
  @Override
  public void afterTextChanged(Editable s) {}
  @Override
  public void beforeTextChanged(CharSequence s, int start,int count, int after) {}
  @Override    
  public void onTextChanged(CharSequence s, int start,int before, int count)
  {
  if(s.length() != 0)
  {
  flag=true;
  flag2=false;
  if(flag==true)
  {
  String result=txt_editText_1.getText().toString().trim();
  txt_editText_2.setText(""+result);
  }
  }
  }
  });
  
  txt_editText_2.addTextChangedListener(new TextWatcher() {
  @Override
  public void afterTextChanged(Editable s) {}
  @Override
  public void beforeTextChanged(CharSequence s, int start,int count, int after) {}
  @Override    
  public void onTextChanged(CharSequence s, int start,int before, int count)
  {
  if(s.length() != 0)
  {
  flag=false;
  flag2=true;
  if(flag2==true)
  {
  String result=txt_editText_2.getText().toString().trim();
  txt_editText_1.setText(""+result);
  }
  }
  }
  });
  </code></pre>
  
  <p>But its not working. So, can anyone give suggestion. </p>