Whenever items from listview are added or deducted the total should be updated. When I add items from listview the grand total is correct but when items are deslected the price of the product shd be deducted from grand total which is not happening. Any solutions?
adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
int index = selectedList.indexOf(ordList.get(adapter.recentItemSelected));
if (index >= 0) {
selectedList.remove(index);
rvOrderBrdAdapter.notifyItemRemoved(index);
return;
} else {
selectedList.add(ordList.get(adapter.recentItemSelected));
rvOrderBrdAdapter.notifyItemInserted(selectedList.size() - 1);
return;
}
}
});
public void totalOrderValue(ArrayList<OrderBrdDataModel> filteredlist) {
double total = 0;
for (int i = 0; i < filteredlist.size(); i++) {
total = total + filteredlist.get(i).getBrdIndividualTotal();
}
totalValue.setText(String.format("%.3f", total));
}