Returning the parent of firebase

0

Helloeveryone,Ihaveaquestionabouthowtogettheparentnodethatwouldbeinthecaseoftheimage-Kt...Imadesomecodebutitdoesnotwork.

protectedvoidonCreate(BundlesavedInstanceState){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 a parameter to another function.

    
asked by anonymous 05.09.2017 / 20:03

1 answer

1

Data recovery in Firebase is done asynchronously, so it is not possible to assign variables out of scope where data recovery is being called.

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());
    }
});
    
06.09.2017 / 01:16