What I am trying to do is
Take my string arraylist values and add them to a double arraylist.
Calculate the sum of the values in the double arraylist and
Set the sum value to a TextView.
private ArrayList<String> totals = new ArrayList<>();
private ArrayList<Double> demototal = new ArrayList<>();
//Parsing the JSON String
try
{
total = itemData.getString(ParseBarcode.KEY_TOTAL);
}catch (JSONException e)
{
e.printStackTrace();
}
// add the parsed total to totals arraylist
totals.add(total);
//converting all values from totals array to Double and add to arraylist demototal
for (int i = 0; i < totals.size(); i++)
{
final String value = totals.get(i);
double total_ary = (double)Math.round((Double.parseDouble(value))*100.0)/100.0;
demototal.add(total_ary);
Toast.makeText(AddInvEst.this, total_ary+"", Toast.LENGTH_SHORT).show();
}
//converting double value to string for setting it to sum textView.
String amount = Double.toString(setArrayListElement(demototal));
textViewSum.setText(amount);//set total text to amount
//calculate amount here we pass setArrayListElement as Double arraylist
private Double setArrayListElement(ArrayList inArray) {
Double amount = 0.0d;
for (int i = 0; i < inArray.size(); i++) {
amount += Double.valueOf(Math.round((Double) inArray.get(i))*100.0)/100.0;
}
return amount;
}
My string arraylist contains values like [51,073,29,620] which is a currency value.