“Firebase Realtime Database Dapatkan Kunci” Kode Jawaban

Firebase Realtime Database Dapatkan Kunci

var ref  = database.child("clubs")
val database_listener = object : ValueEventListener {
        override fun onDataChange(dataSnapshot: DataSnapshot) {
            for (ds in dataSnapshot.children) {
                val key = ds.key
           }
        }
     }
   ref.addValueEventListener(database_listener)
Vitalik-Hakim

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

Jawaban yang mirip dengan “Firebase Realtime Database Dapatkan Kunci”

Pertanyaan yang mirip dengan “Firebase Realtime Database Dapatkan Kunci”

Lebih banyak jawaban terkait untuk “Firebase Realtime Database Dapatkan Kunci” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya