-1

my code is used for correcting a discount on edittext but i got these error. i think its because infinite loop. can someone help me. here is the code

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): Explicit concurrent mark sweep GC freed 19797(1048KB) AllocSpace objects, 4(724KB) LOS objects, 37% free, 26MB/42MB, paused 987us total 45.773ms 04-06 13:29:35.041: I/art(11644): Explicit concurrent mark sweep GC freed 17983(1035KB) AllocSpace objects, 2(32KB) LOS objects, 38% free, 25MB/41MB, paused 1.868ms total 45.424ms 04-06 13:29:35.427: I/art(11644): Explicit concurrent mark sweep GC freed 8851(352KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 25MB/41MB, paused 2.677ms total 45.746ms 04-06 13:29:35.823: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 25MB/41MB, paused 3.678ms total 48.588ms 04-06 13:29:36.245: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 26MB/42MB, paused 4.653ms total 53.182ms 04-06 13:29:36.688: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 5.525ms total 59.075ms 04-06 13:29:37.147: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 6.517ms total 59.858ms 04-06 13:29:37.642: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 7.172ms total 62.052ms 04-06 13:29:38.132: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 8.209ms total 65.912ms 04-06 13:29:38.649: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 9.324ms total 71.601ms 04-06 13:29:39.199: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 10.410ms total 75.473ms 04-06 13:29:39.744: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 26MB/42MB, paused 11.255ms total 76.567ms 04-06 13:29:40.323: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 27MB/43MB, paused 12.545ms total 81.347ms 04-06 13:29:40.934: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 13.400ms total 89.937ms 04-06 13:29:41.554: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 14.143ms total 86.915ms 04-06 13:29:42.197: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 15.285ms total 91.488ms 04-06 13:29:42.861: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 15.963ms total 94.276ms 04-06 13:29:43.541: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 17.272ms total 100.209ms 04-06 13:29:44.335: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 27MB/43MB, paused 28.801ms total 120.016ms 04-06 13:29:45.057: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 28MB/44MB, paused 18.840ms total 106.458ms 04-06 13:29:45.782: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 28MB/44MB, paused 20.298ms total 110.636ms 04-06 13:29:46.520: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 28MB/44MB, paused 20.687ms total 113.699ms 04-06 13:29:47.276: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 28MB/44MB, paused 21.898ms total 116.993ms 04-06 13:29:48.046: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 28MB/44MB, paused 22.568ms total 118.070ms 04-06 13:29:48.833: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 28MB/44MB, paused 23.528ms total 121.328ms 04-06 13:29:49.652: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 28MB/44MB, paused 24.310ms total 125.187ms 04-06 13:29:50.522: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 25.298ms total 139.861ms 04-06 13:29:51.436: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 26.244ms total 137.324ms 04-06 13:29:52.347: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 28.023ms total 139.690ms 04-06 13:29:53.258: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 28.505ms total 148.240ms 04-06 13:29:54.173: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 28.942ms total 143.808ms 04-06 13:29:55.114: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 29MB/45MB, paused 30.406ms total 153.420ms 04-06 13:29:56.049: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 34% free, 29MB/45MB, paused 31.116ms total 150.076ms 04-06 13:29:57.052: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 34% free, 29MB/45MB, paused 31.684ms total 154.811ms 04-06 13:29:58.097: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 34% free, 30MB/46MB, paused 33.261ms total 178.936ms 04-06 13:29:59.136: I/art(11644): Explicit concurrent mark sweep GC freed 8847(351KB) AllocSpace objects, 0(0B) LOS objects, 34% free, 30MB/46MB, paused 33.617ms total 160.683ms

Rince Thomas
  • 4,158
  • 5
  • 25
  • 44

1 Answers1

1

You can't change salesorder_disc4 text inside its onTextChanged, this will case infinite loop.

use afterTextChanged instead.

EDIT:

TextWatcher functions explained

Community
  • 1
  • 1
naif.ult
  • 186
  • 6