Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

firebase realtime database get key

//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) { }
});
Comment

firebase realtime database get key

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)
Comment

PREVIOUS NEXT
Code Example
Java :: java variable 
Java :: djava days between two dates 
Java :: Java 2-dimensional Array 
Java :: multiple spinner android 
Java :: processing pi 
Java :: sort java array 
Java :: LRU Cache java 
Java :: increment an array java 
Java :: hash map java 
Java :: url string from url java 
Java :: call by value and call by reference in java 
Java :: Alerter for java 
Java :: parameterized constructor java 
Java :: java array quick sort 
Java :: java streams 
Java :: what is construct in java 
Java :: position of an element in infinite sorted array 
Java :: positive numbers in array 
Java :: java servlet life cycle 
Java :: new date api in java 8 
Java :: try catch block 
Java :: arraylist methods in java 
Java :: my canvas java 
Java :: Java TestNG Data Provider example 
Java :: calculate the area of two squares in java by using a method 
Java :: JAVA Declaration Statements 
Java :: first none duplicated char 
Java :: strictfp java example 
Java :: Which of the below is a correct identifier for a method name in Java * 2 points 0start #stop 0_start *start# 
Java :: android java convert boolean to string 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =