我想更新我的ArrayList,其中包含2个编辑文本和1个文本视图上的文本更改地图。
这是我的Text Watcher代码。
private void calculateAndShow(double wt, double rt, double mk) {
String w = weightLine.getText().toString();
wt = Double.parseDouble(w);
double NetRate = (double) Math.round((rt + mk) * 100.0) / 100.0;
double Total = (double) Math.round(((NetRate / 10) * wt) * 100.0) / 100.0;
netRate.setText(NetRate + "");
itemtotal.setText(Total + "");
itemselected.put("rate", String.valueOf(rt));
itemselected.put("makingAmt", String.valueOf(mk));
itemselected.put("net_rate", String.valueOf(NetRate));
itemselected.put("itemTotal",String.valueOf(Total));
}
private TextWatcher rateTextWatcher = 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 rate = rateAmount.getText().toString();
rt = Double.parseDouble(rate);
itemselected.put("rate", String.valueOf(rt));
calculateAndShow(wt, rt, mk);
rates.add(rate);
}
};
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);
itemselected.put("makingAmt", String.valueOf(mk));
calculateAndShow(wt, rt, mk);
mkCharges.add(mkAmt);
}
};
//Text watcher for sum total of all selected items
private TextWatcher totalTextWatcher = 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) {
int id = 0;
id = (int) itemtotal.getTag();
String itemTot = itemtotal.getText().toString();
if (id >= 0 && id <= totals.size()) {
totals.set(id - 1, itemTot);
double[] doubleList = new double[totals.size()];
double newsum = 0.0d;
for (int i = 0; i < totals.size(); ++i) {
doubleList[i] = Double.parseDouble(totals.get(i));
newsum += (double) Math.round((doubleList[i]) * 100.0) / 100.0;
}
textViewSum.setText(((double) Math.round((newsum * (0.02) + newsum) * 100.0) / 100.0) + "");//set total text to sum
textViewVat.setText(((double) Math.round((newsum * (0.02)) * 100.0) / 100.0) + "");
}
}
};
这是我的地图和数组列表实现。我将所有值存储在地图中,然后将地图存储在数组列表中。我想要的是每次文本都更新数组列表中的地图值变化。
private ArrayList<Map<String, String>> itemData = new ArrayList<>();
private Map<String, String> itemselected = new HashMap<>();
private void itemSelectedArray() {
int index =0;
if(invEstSwitch.isChecked())
{
billType = textViewEstimate.getText().toString();
}else{
billType =textViewInvoice.getText().toString();
}
itemselected.put("invoiceNo", textViewInvNo.getText().toString());//d
itemselected.put("cstName", textViewCstName.getText().toString());//d
itemselected.put("contact", textViewCstph.getText().toString());//d
itemselected.put("barcode", barCode.getText().toString());//d
itemselected.put("desc", itemDesc.getText().toString());//d
itemselected.put("weight", weightLine.getText().toString());//d
itemselected.put("rate", rateAmount.getText().toString());//d
itemselected.put("makingAmt", makingAmount.getText().toString());//d
itemselected.put("net_rate", netRate.getText().toString());//d
itemselected.put("itemTotal", itemtotal.getText().toString());//d
itemselected.put("vat", textViewVat.getText().toString());//d
itemselected.put("sum_total", textViewSum.getText().toString());//d
itemselected.put("bill_type", billType);//d
itemData.add(index, itemselected);
index++;
}