2015-12-09 3 views
1

Это мой журнал для 1-го изменения текстаВсе объекты json обновляются при изменении текста?

[{ 
    "custInfo": "Anup 8600931386", 
    "rate": "24032", 
    "weight": "21.00000", 
    "makingAmt": "232", 
    "description": "GENTS ANGTHI 22k NO STONE", 
    "sum_total": "50954.4", 
    "vat": "", 
    "itemTotal": "50954.4", 
    "barcode": "BQSP78BB", 
    "net_rate": "24264.0", 
    "date": "09-12-2015", 
    "invoiceNo": "1", 
    "bill_type": "Estimate" 
}] 

Теперь, когда я добавить еще одну запись предыдущий элемент также получает updated.This является журнал после того, как 2-го входа.

[{ 
    "custInfo": "Anup 8600931386", 
    "rate": "24052", 
    "weight": "12.00000", 
    "makingAmt": "228", 
    "description": "LADIES TOP 22K NO STONE", 
    "sum_total": "29136.0", 
    "vat": "", 
    "itemTotal": "29136.0", 
    "barcode": "BQSP82BB", 
    "net_rate": "24280.0", 
    "date": "09-12-2015", 
    "invoiceNo": "1", 
    "bill_type": "Estimate" 
}, { 
    "custInfo": "Anup 8600931386", 
    "rate": "24052", 
    "weight": "12.00000", 
    "makingAmt": "228", 
    "description": "LADIES TOP 22K NO STONE", 
    "sum_total": "29136.0", 
    "vat": "", 
    "itemTotal": "29136.0", 
    "barcode": "BQSP82BB", 
    "net_rate": "24280.0", 
    "date": "09-12-2015", 
    "invoiceNo": "1", 
    "bill_type": "Estimate" 
}] 

Это моя реализация текста наблюдающий и код, который обновляет значения внутри после текста изменяется().

private TextWatcher mkAmountTextWatcher = new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      String mkAmt = makingAmount.getText().toString(); 
      mk = Double.parseDouble(mkAmt); 
      calculateAndShow(wt, rt, mk); 

      int mid = (int) newRow.getTag()-1; 
      if ((mid<0) || (mid>itemSelectedJson.length())){ 
       return; 
      } 
      try{ 
       itemSelectedJson.getJSONObject(mid).put("makingAmt",mkAmt); 

       Log.d("MAKING_TW", itemSelectedJson.toString()); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    }; 

Это код для создания массива JSON.

private void createJsonArray() { 
    billType = (invEstSwitch.isChecked() ? textViewEstimate : textViewInvoice) 
      .getText().toString(); 
    String invNumber = textViewInvNo.getText().toString(); 
    String bcode = barCode.getText().toString(); 
    String description = itemDesc.getText().toString(); 
    String wt = weightLine.getText().toString(); 
    String rateAmt = rateAmount.getText().toString(); 
    String making = makingAmount.getText().toString(); 
    String netr = netRate.getText().toString(); 
    String iTotal = itemtotal.getText().toString(); 
    String vatAmt = textViewVat.getText().toString(); 
    String sumAmt = textViewSum.getText().toString(); 
    String crtDate = textViewCurrentDate.getText().toString(); 
    try { 
     jsonObject.put("custInfo", custSelected.toString()); 
     jsonObject.put("invoiceNo", invNumber); 
     jsonObject.put("barcode", bcode); 
     jsonObject.put("description", description); 
     jsonObject.put("weight", wt); 
     jsonObject.put("rate", rateAmt); 
     jsonObject.put("makingAmt", making); 
     jsonObject.put("net_rate", netr); 
     jsonObject.put("itemTotal", iTotal); 
     jsonObject.put("vat", vatAmt); 
     jsonObject.put("sum_total", sumAmt); 
     jsonObject.put("bill_type", billType); 
     jsonObject.put("date", crtDate); 


    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
    try { 

     itemSelectedJson.put(index, jsonObject); 
     index++; 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
} 

ответ

0

В этом методе createJsonArray() вы не используете тот же JSONObject каждый раз. Вот почему вы получаете тот же контент снова и снова.

Сначала попробуйте инициализировать метод jsonObject в createJsonArray(), тогда я думаю, он будет работать.

Смежные вопросы