I’m creating a delivery tip tracker application for android, and using SQLite to store all of the customers’ data. I have almost everything working that I need except for a running total of my tips for the night. My code is as follows:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.contact_entry, null);
TextView name= (TextView) convertView.findViewById(R.id.contactName);
TextView contact = (TextView) convertView.findViewById(R.id.contact);
TextView address = (TextView) convertView.findViewById(R.id.addressConverted);
TextView orderTotal = (TextView) convertView.findViewById(R.id.orderTotalConverted);
TextView amountReceived = (TextView) convertView.findViewById(R.id.amountReceivedConverted);
TextView tip = (TextView) convertView.findViewById(R.id.tipConverted);
TextView mileage = (TextView) convertView.findViewById(R.id.mileageConverted);
TextView grandTotal = (TextView) convertView.findViewById(R.id.grandTotalConverted);
Button delete = (Button) convertView.findViewById(R.id.delete);
PhoneBook list = contactList.get(position);
name.setText(list.getName());
contact.setText(list.getPhoneNumber());
address.setText(list.getAddress());
orderTotal.setText(list.getOrderTotal());
amountReceived.setText(list.getAmountReceived());
tip.setText(list.getTip());
mileage.setText(list.getMileage());
grandTotal.setText(list.getGrandTotal());
delete.setOnClickListener(new ListItemClickListener(position, list));
TextView deliveryNumber = (TextView) convertView.findViewById(R.id.deliveryNum);
deliveryNumber.setText("Delivery # " + (position + 1));
TextView runningTotal = (TextView) convertView.findViewById(R.id.runningTotal);
return convertView;
}
When the user clicks the “Save” button in the main window, all of the information for the delivery is saved to the database and displayed in a listview in a separate window. So if I have 3 deliveries for the night, I have 3 listviews stacked on top of each other. I’m trying to create a TextView called “runningTotal” that displays the running total of my tips for the night, each which is stored in a variable called grandTotal. But I can’t figure out how to sum up the grandTotal column to get that information. Any help would be greatly appreciated! It’s for a final project in Mobile App Development. I ask the question on StackOverflow, and pretty much get treated like I’m an idiot. Maybe that’s partially true, but I just have no idea how to do it. I’ve found ways to create a method to get the sum, but no idea where to put that method in my code, or how to save it to a textview.