2015-04-06 63 views
-1

我的代碼用於更正edittext上的折扣,但我得到了這些錯誤。我認爲它是因爲無限循環。 有人可以幫助我。 這裏是代碼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 /技術(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.868毫秒總計45.424毫秒 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 %free,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)AllocSp ace對象,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):顯式併發nt標記掃描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.328 ms 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.244 ms總計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已釋放8 847(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

回答

1

你不能改變它的onTextChangedsalesorder_disc4文本,這將區分無限循環。

改爲使用afterTextChanged

編輯:

TextWatcher functions explained

+0

我將它添加到afterTextChanged salesorder_disc4.setText(temp1目錄),但仍錯誤 – user3011493 2015-04-06 06:53:59

+0

您可以發佈更新後的代碼? – 2015-04-06 08:54:04