Android兩個EditText同時設置TextChangedListener後,會使程序進入死循環,解決方法如下:
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);
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11