当前位置: 代码迷 >> Android >> Android 避免二个相互影响的 EditText 死循环
  详细解决方案

Android 避免二个相互影响的 EditText 死循环

热度:406   发布时间:2016-05-01 12:24:18.0
Android 避免2个相互影响的 EditText 死循环

两个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);




  相关解决方案