Problem recovering firebase values for list

Asked

Viewed 30 times

0

I am making a list, and on this list I pull up the following information id, idPostagem, description, usergroup and photoUsuario.

However to popular(add) data to this list I am using the following code snippet within an Activity:

        itensSalvosRef = ConfiguracaoFirebase.getFirebase().child("itens-salvos").child(idUsuarioLogado);        

        @Override
        protected void onStart() {
            super.onStart();
            listarItensSalvos();
        }    

        private void listarItensSalvos() {

            valueEventListener = itensSalvosRef.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    listaItemSalvo.clear();

                    for (DataSnapshot ds : dataSnapshot.getChildren()) {

                        listaItemSalvo.add(ds.getValue(ItemSalvo.class));

                    }

                    Collections.reverse(listaItemSalvo);
                    itensSalvosAdapter.notifyDataSetChanged();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

        }

Firebase structure:

inserir a descrição da imagem aqui

The idea is to recover all values, but it only recovers the name Suario, as shown in the photo below:

inserir a descrição da imagem aqui

What I’m doing wrong to the popular (add values) to that list?

  • The names of your class properties listaItemSalvo are totally different from your firebase bank, only the field nomeUsuario is correct, so only it is coming filled...

  • @Matheusribeiro Nossa... kkk was just that, I was so focused on something else that I didn’t think about the obvious, thank you. If you want to reply so I can mark it as a response, you can reply!

1 answer

1


The names of your property class listItemSalvo are totally different from your firebase database, only the field userName is correct, so only it is coming filled in...

Your target list class looks like this:

descricao
fotoPostagem
id
nomeUsuario

But the right thing, I believe, is that it should be

feedDescricao
feedFoto
feedId
nomeUsuario

Always try to create your classes giving names to the properties equal the fields of the bank, that is, always try to mirror the bank in your class, this facilitates the understanding and also leaves everything more practical.

  • Thank you! I really didn’t even pay attention!

Browser other questions tagged

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