Receive a single data from a Firebase node

0

I would like to know how to recover from FireBase a single FireBase data, I used the EventListener structure by mounting the object and pulling only one of the data, but when I run the error app and it closes, it may be an error in the specified path, but I do not know how to proceed. How do I retrieve only 1 of the data from a node ???

Fragment

public class fragmentPerfil extends Fragment {
private DatabaseReference databaseReference;
private FirebaseAuth autenticacao;
private TextView nome;
private String usuarioLogado;

public fragmentPerfil() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_noticias, container, false);

    nome = (TextView) view.findViewById(R.id.txt_nome);

    autenticacao = FirebaseConfig.getAutenticacao();
    autenticacao.getCurrentUser();
    usuarioLogado = autenticacao.getCurrentUser().getUid();
    databaseReference = FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado);
    databaseReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Usuarios user = dataSnapshot.getValue(Usuarios.class);
            nome.setText(user.getNome());

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });



    return view;
  }

}

    
asked by anonymous 08.06.2017 / 04:16

1 answer

0

Hello,

FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado);

It will return the entire "Users" object, if you want to return only the "name", do so:

FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado).child("nome");

Then your return on

 public void onDataChange(DataSnapshot dataSnapshot) {

It will be a string. To get it it would look like this:

String nome = (String) dataSnapshot.getValue();
    
08.06.2017 / 22:36