0
listaPedidoComprador.setLayoutManager(new LinearLayoutManager(this));
listaPedidoComprador.setHasFixedSize(true);
adapterPedidoComprador = new AdapterPedidoComprador(itensCarrinho2);
System.out.println(String.format("quantidade que está no itensCarrinho pro adapter: %d ", itensCarrinho.size()));
listaPedidoComprador.setAdapter(adapterPedidoComprador);
adapterPedidoComprador.setOnItemClickListener(new AdapterPedidoComprador.OnItemClickListener() {
@Override
public void onAddClick(int position) {
ItemPedido itemPedido = itensCarrinho2.get(position);
Toast.makeText(CompradorPedidos.this, itemPedido.getNomeProduto(), Toast.LENGTH_SHORT).show();
}
});
recuperarItemPedidoJamilton();
System.out.println(String.format("pedidos recuperados: %d", produtos.size()));
System.out.println(String.format("quantidade que está no carrinho: %d nesse exato momento fora do método", itensCarrinho.size()));
System.out.println(String.format("quantidade que está no carrinho2: %d nesse exato momento fora do método", itensCarrinho2.size()));
System.out.println("eae bb");
}
@Override
protected void onStart() {
super.onStart();
//recuperarItemPedidoJamilton();
}
private void recuperarItemPedidoJamilton() {
DatabaseReference produtoref = firebaseRef
.child("pedidos_usuario")
.child(idUsuarioLogado);
produtoref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
pedidoRecuperado = dataSnapshot.getValue(Pedido.class);
itensCarrinho2 = pedidoRecuperado.getItens();
adapterPedidoComprador.notifyDataSetChanged();
System.out.println(String.format("quantidade que está no carrinhoJamilton: %d nesse exato momento", itensCarrinho2.size()));
} else {
//Toast.makeText(CompradorPedidos.this, "Seu carrinho está vazio", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
// Error
}
});
System.out.println(String.format("quantidade que está no carrinhoJamiltonfora: %d nesse exato momento", itensCarrinho.size()));
}
As you can see, I’m trying to put this list on the Adapter, but it’s not right because this list is apparently empty. I do not understand what is happening, since I put a println inside the method and it is returning that there are items inside the list!!
I have tried to leave itensCarrinho2 (list I am trying to fill) static, but I can’t work well so there are cases where it is necessary to delete the list, because it is a shopping cart, and when confirming or removing an item from the cart, cannot be removed from the list that is static... I suppose...
Hello. Please, detail better the situation that is happening. I understand that you have added a list to Adapter that should initially be empty, and are not adding the new item to it before calling
notifyDataSetChanged()
Adapter.– Piovezan
I’m trying to put the itensCarrinho2 list to my Adapter, as you can see in the code, I call a method to fill this list (recoveryItemPedidoJamilton();) and I know that this list is being filled in by the println I put inside (it shows that there are items in the list using itensCarrinho2.size.), but by the time I call pro Adapter, it is empty
– João Vitor