Ethan Hunt
Ethan Hunt

Reputation: 1

New Child is not created in firebase

i am trying to save new files in numbered order. so there is a count child it get updated but no new child is created this is the code

 databaseReference.child("AdminList").addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            long key= (long) dataSnapshot.child("count").getValue();
            databaseReference.child("AdminList").child("count").setValue(key+1);
            databaseReference.child("AdminList").child(String.valueOf(key+1)).child("uid").setValue(uid);
            databaseReference.child("AdminList").child(String.valueOf(key+1)).child("Aname").setValue(fname);
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });``

Upvotes: 0

Views: 611

Answers (2)

Suhayl SH
Suhayl SH

Reputation: 1223

Use push() to create new child nodes:

databaseReference.child("childName").push();

Upvotes: 0

BlackHatSamurai
BlackHatSamurai

Reputation: 23483

You are trying to store your data in a "continuous" manner, which is something that JSON objects just aren't designed do. If you are looking for an ordered list, use the priorities property, or you can order the data on the client side. This means that you can just store the data, and then either order client-side, or prioritize the children. I would look to do something like:

databaseReference.child("AdminList").child("uid").setValue(uid);

Upvotes: 1

Related Questions