Firebase Realtime Database Dapatkan Kunci
//firebase reference
DatabaseReference mRef = FirebaseDatabase.getInstance().getReference();
//set THe_strOX's database contents from the question
mRef.child("clubs").child("-KLpcURDV68BcbAvlPFy").child("dept").setValue("abc");
mRef.child("clubs").child("-KLpcURDV68BcbAvlPFy").child("desc").setValue("xyz");
mRef.child("clubs").child("-KLpcURDV68BcbAvlPFy").child("name").setValue("efg");
mRef.child("clubs").child("-asdasdasddsad").child("dept").setValue("asda");
mRef.child("clubs").child("-asdasdasddsad").child("desc").setValue("asd");
mRef.child("clubs").child("-asdasdasddsad").child("name").setValue("adddd");
//
mRef.child("clubs").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, String s)
{
if (dataSnapshot.exists())
{
String pushkey = dataSnapshot.getKey();
mRef.child("clubs").child(pushkey).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, String s)
{
if (dataSnapshot.exists())
{
if (dataSnapshot.getKey().toString().equals("name")) {
//edit efg to any desired value
if (dataSnapshot.getValue().toString().equals("efg")) {
Toast.makeText(MainActivity.this, pushkey, Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, String s) { }
@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) { }
@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @androidx.annotation.Nullable String previousChildName) { }
@Override
public void onCancelled(@NonNull DatabaseError error) { }
});
}
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, String s) { }
@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) { }
@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @androidx.annotation.Nullable String previousChildName) { }
@Override
public void onCancelled(@NonNull DatabaseError error) { }
});
Vitalik-Hakim