Returning the firebase Father node

Asked

Viewed 188 times

0

inserir a descrição da imagem aqui

Hello guys I’m having a doubt on how to catch the parent node that would be in the case of the image o -Kt... I made some codes but not right.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_criar_cardapio);
    codigo = (TextView) findViewById(R.id.textView3);
    ref.child("Mesas").getParent();}

I want to assign this String to a variable to pass as parameter to another function.

1 answer

1

Data recovery in Firebase is done asynchronously, this means that it is not possible to assign variables outside the scope where this being called data recovery.

codigo = (TextView) findViewById(R.id.textView3);

reference = LibraryClass.getFirebase().child("Mesas");
reference.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

        DataSnapshot snapshot : dataSnapshot.getChildren();

        Log.i("TAG", "key" + snapshot.getKey()); // -Kt8cQVVuvZQ1BYFp7hX

        codigo.setText(snapshot.getKey()); // -Kt8cQVVuvZQ1BYFp7hX
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        Log.e("TAG", databaseError.getMessage());
    }
});
  • I have a class called table and wanted to use this function

  • You can use, but it has to be within the call scope in Firebase.

Browser other questions tagged

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