REA*_*O G 1 java recursion android textview android-edittext
这里有新的SO用户,相当新的Java.运行此命令时,它会因java.lang.stackoverflow错误而崩溃.我很确定它是递归的,但我无法弄清楚为什么.我已经尝试逐步调试但是我收到一个错误,它无法找到类文件.这是代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
newPrice.addTextChangedListener(tradeWatch);
tradeIn.addTextChangedListener(tradeWatch);
acc.addTextChangedListener(tradeWatch);
tradeDif.addTextChangedListener(tradeWatch);
}
TextWatcher tradeWatch = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
calcTrade();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
};
private void calcTrade() {
Editable eValue1 = newPrice.getText(), eValue2 = tradeIn.getText(), eValue3 = acc.getText();
Double value1 = 0.0, value2 = 0.0, value3 = 0.0, result = 0.0;
if (eValue1 != null)
value1 = toDouble(eValue1);
if (eValue2 != null)
value2 = toDouble(eValue2);
if (eValue3 != null)
value3 = toDouble(eValue3);
if (value1 != null && value2 != null && value3 != null)
result = value1 - (value2 + value3);
tradeDif.setText(result.toString());
}
private double toDouble(final Editable editable) {
final String content = editable.toString();
if (content.isEmpty()) {
return 0;
}
return Double.parseDouble(content);
}
public void nextPage(View v) {
Intent i=new Intent(this, Activity2.class);
startActivity(i);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是线:
tradeDif.setText(result.toString());
Run Code Online (Sandbox Code Playgroud)
您更改文本并导致调用
afterTextChanged(Editable s)
Run Code Online (Sandbox Code Playgroud)
一次又一次.
归档时间: |
|
查看次数: |
213 次 |
最近记录: |