两个EditText同时设置TextChangedListener后,会使程序进入死循环,解决方法如下:
[java]
etExchangeRateEn = (EditText) findViewById(R.id.etExchangeRateEn);
etExchangeRateCn = (EditText) findViewById(R.id.etExchangeRateCn);
twEN = new TextWatcher()
{
@Override
public void afterTextChanged(Editable s)
{
etExchangeRateCn.addTextChangedListener(twCN);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
etExchangeRateCn.setText( "CN");
}
};
twCN = new TextWatcher()
{
@Override
public void afterTextChanged(Editable s)
{
etExchangeRateEn.addTextChangedListener(twEN);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
etExchangeRateEn.setText("EN");
}
};
etExchangeRateEn.addTextChangedListener(twEN);
etExchangeRateCn.addTextChangedListener(twCN);