我的代码用于纠正edittext上的折扣,但我收到了这些错误。我认为它是因为无限循环。 有人能帮我吗。 这是代码
salesorder_disc4.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().equals(""))
{
double disc = Double.parseDouble(s.toString());
values6[position]= (int) disc;
double disc_amount = 0;
int multiUnit = values7b.get(position).get(values5[position]);
double gross_sub = values7[position] * multiUnit * values3[position];
//values6[position]= disc;
if(salesorder_disc_4_spinner.getSelectedItemPosition()==0) {
disc_amount = (disc * values7[position]) / 100;
if (values7[position] - disc_amount > values10[position]){
disc = Double.parseDouble(s.toString());
}
else if (values7[position] - disc_amount <= values10[position]){
int new_discount = (int) Math.abs(((values7[position] - values10[position])/values7[position])*100);
String temp1 = String.valueOf(new_discount);
salesorder_disc4.setText(String.valueOf(temp1));
}
}
else if(salesorder_disc_4_spinner.getSelectedItemPosition()==1) {
if (disc > gross_sub){
salesorder_disc4.setText(String.valueOf((int)gross_sub));
}
else if (values7[position] - disc < values10[position]){
int new_discount = (int) Math.abs((values7[position] - values10[position])*multiUnit);
salesorder_disc4.setText(String.valueOf(new_discount));
}
}
else if(salesorder_disc_4_spinner.getSelectedItemPosition()==2) {
if (disc > gross_sub){
salesorder_disc4.setText(String.valueOf((int)gross_sub));
}
else if (gross_sub - disc < values10[position] * Integer.parseInt(salesorder_qty4.getText().toString())){
int new_discount = (int) Math.abs((values7[position] - values10[position]) * Integer.parseInt(salesorder_qty4.getText().toString())*multiUnit);
salesorder_disc4.setText(String.valueOf(new_discount));
}
}
}
//else{ salesorder_disc4.setText("0"); }
//salesorder_price4.setText(total(position, salesorder_disc_4_spinner.getSelectedItemPosition()));
total(position, salesorder_disc_4_spinner.getSelectedItemPosition());
grandtotal();
tabel_toko.updateCartDisc(values0[position], values6[position], values12[position]);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable s) { }
});
logcat的
04-06 13:29:34.654:I / art(11644):显式并发标记扫描GC释放19797(1048KB)AllocSpace对象,4(724KB)LOS对象,37%免费,26MB / 42MB,暂停987us 45.773ms 04-06 13:29:35.041:I / art(11644):显式并发标记扫描GC释放17983(1035KB)AllocSpace对象,2(32KB)LOS对象,38%可用,25MB / 41MB,暂停1.868ms总计45.424ms 04-06 13:29:35.427:I / art(11644):显式并发标记扫描GC释放8851(352KB)AllocSpace对象,0(0B)LOS对象,38%免费,25MB / 41MB,暂停2.677ms总计45.746ms 04-06 13:29:35.823:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,38%免费,25MB / 41MB,暂停3.678ms总计48.588ms 04-06 13:29:36.245:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,38%免费,26MB / 42MB,暂停4.653ms总计53.182ms 04-06 13:29:36.688:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停5.525ms总计59.075ms 04-06 13:29:37.147:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停6.517ms总计59.858ms 04-06 13:29:37.642:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停7.172ms总计62.052ms 04-06 13:29:38.132:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停8.209ms总计65.912ms 04-06 13:29:38.649:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停9.324ms总计71.601ms 04-06 13:29:39.199:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停10.410ms总计75.473ms 04-06 13:29:39.744:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%免费,26MB / 42MB,暂停11.255ms总计76.567ms 04-06 13:29:40.323:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,37%空闲,27MB / 43MB,暂停12.545ms总计81.347ms 04-06 13:29:40.934:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,27MB / 43MB,暂停13.400ms总计89.937ms 04-06 13:29:41.554:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%免费,27MB / 43MB,暂停14.143ms总计86.915ms 04-06 13:29:42.197:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%免费,27MB / 43MB,暂停15.285ms总计91.488ms 04-06 13:29:42.861:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,27MB / 43MB,暂停15.963ms总计94.276ms 04-06 13:29:43.541:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,27MB / 43MB,暂停17.272ms总计100.209ms 04-06 13:29:44.335:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,27MB / 43MB,暂停28.801ms总计120.016ms 04-06 13:29:45.057:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,28MB / 44MB,暂停18.840ms总计106.458ms 04-06 13:29:45.782:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,28MB / 44MB,暂停20.298ms总计110.636ms 04-06 13:29:46.520:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,36%空闲,28MB / 44MB,暂停20.687ms总计113.699ms 04-06 13:29:47.276:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,28MB / 44MB,暂停21.898ms总计116.993ms 04-06 13:29:48.046:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,28MB / 44MB,暂停22.568ms总计118.070ms 04-06 13:29:48.833:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,28MB / 44MB,暂停23.528ms总计121.328ms 04-06 13:29:49.652:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,28MB / 44MB,暂停24.310ms总计125.187ms 04-06 13:29:50.522:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,29MB / 45MB,暂停25.298ms总计139.861ms 04-06 13:29:51.436:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,29MB / 45MB,暂停26.244ms总计137.324ms 04-06 13:29:52.347:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%免费,29MB / 45MB,暂停28.023ms总计139.690ms 04-06 13:29:53.258:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%免费,29MB / 45MB,暂停28.505ms总计148.240ms 04-06 13:29:54.173:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%空闲,29MB / 45MB,暂停28.942ms总计143.808ms 04-06 13:29:55.114:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,35%免费,29MB / 45MB,暂停30.406ms总计153.420ms 04-06 13:29:56.049:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,34%空闲,29MB / 45MB,暂停31.116ms总计150.076ms 04-06 13:29:57.052:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,34%免费,29MB / 45MB,暂停31.684ms总计154.811ms 04-06 13:29:58.097:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,34%免费,30MB / 46MB,暂停33.261ms总计178.936ms 04-06 13:29:59.136:I / art(11644):显式并发标记扫描GC释放8847(351KB)AllocSpace对象,0(0B)LOS对象,34%免费,30MB / 46MB,暂停33.617ms总计160.683ms
答案 0 :(得分:1)
您无法在其salesorder_disc4
内更改onTextChanged
文字,这将无限循环。
改为使用afterTextChanged
。
编辑: