I am making an ArrayList
that contains Map
values. itemData
is my ArrayList
that contains itemselected
, which is a map. Then, because I want to send this array to my PHP code, I am converting itemData
into a JSONArray
. Then parsing the array in my PHP script and inserting those individual values into a MySQL database.
private ArrayList<Map<String, String>> itemData = new ArrayList<>();
private Map<String, String> itemselected = new HashMap<>();
JSONArray itemSelectedJson = new JSONArray();
private void selectedItems() {
if(invEstSwitch.isChecked())
{
billType = textViewEstimate.getText().toString();
}else{
billType = textViewInvoice.getText().toString();
}
itemselected.put("custInfo",custSelected.toString());
itemselected.put("invoiceNo", textViewInvNo.getText().toString());
itemselected.put("barcode", barCode.getText().toString());
itemselected.put("desc", itemDesc.getText().toString());
itemselected.put("weight", weightLine.getText().toString());
itemselected.put("rate", rateAmount.getText().toString());
itemselected.put("makingAmt", makingAmount.getText().toString());
itemselected.put("net_rate", netRate.getText().toString());
itemselected.put("itemTotal", itemtotal.getText().toString());
itemselected.put("vat", textViewVat.getText().toString());
itemselected.put("sum_total", textViewSum.getText().toString());
itemselected.put("bill_type", billType);
itemselected.put("date", textViewCurrentDate.getText().toString());
//Add the map to the Array
itemData.add(index, itemselected);
itemSelectedJson= new JSONArray(Arrays.asList(itemData));
index++;
}
The code is pretty straightforward, but I am interested in any possible improvement. I am sure there is a better way to do it.