Delete position of array

Asked

Viewed 27 times

-1

Good afternoon

I have an order app, record the items within an array when I need to delete an item from the request, somehow the array size does not decrease for example I registered 3 items and delete one, the size of the array is still 3 and if I don’t add another item to complete, the app hangs.

I’ve tried some things:

int size = request items(). size -1;

pedidoList.remove(lastindex)

Still giving trouble. what could be?

  • pedido.itens() and pedidoList reference the same object?

  • Hello! request.items is a request class facility that accesses the item attribute which is the arraylist. pedidoList is another arrayList of the Requests class I use to list orders in Recycler view. I don’t know if I can understand...

1 answer

0

Hello,

It turns out that you put the current value of the order quantity into the variable size and after that, she is not changed, to correct, you can call him again:

int size = pedido.itens().size -1;

pedidoList.remove(lastindex);

size = pedido.itens().size -1;

But this way you are, you could create the size after removing the item, as you do not use the variable size before calling the method remove.

  • Good evening. I’m sorry, I don’t quite understand! Could I use it that way? decrease by 1 of the size of the array but have to call after removing the item, right?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.