0
I put the code down on onCreate
and onResume
, but of the problem when putting in the onResume
. Whenever I return/leave the editing screen, onResume
goes into action and goes through the whole list again.
Example: I add item 1, the TextView
with the value, I go back to the edit screen and add item 2, calling the onResume
and adds item 1 again and then adds item 2 in the sum and so on.
How can I make the sum start from the item I added to not occur this problem ?
@Override protected void onResume() {
super.onResume();
TextView txtTotal = (TextView)findViewById(R.id.txtTotal);
for(int i = 0; i < itemList.size(); i++) {
totalItems = totalItems + itemList.get(i).getPreco(); } txtTotal.setText(String.valueOf(totalItems)); }
I first get the bank list on onCreate, using:
realm = Realm.getDefaultInstance();
itemList = realm.where(Item.class).findAll();
Look I always instate my components in onCreate. To tell you the truth I’ve never seen anyone instantiating anywhere else, unless it’s an adapter or something
– Stênio Barroso de Moraes