title: How do I auto increment and make index id for a tree in firebase database?
body: <p>This is the code I have written, but It is not working.</p>
  <pre><code>    EditText plant = (EditText)findViewById(R.id.plantname);
      String pn = plant.getText().toString();
  
      FirebaseAuth mAuth;
      mAuth = FirebaseAuth.getInstance();
      FirebaseUser currentFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
  
  
  
  
      FirebaseDatabase database = FirebaseDatabase.getInstance();
      myref  = database.getReference(&quot;Plants&quot;).child(String.valueOf(id+1));
  
  
  
      myref.child(&quot;Name&quot;).setValue(pn);
      myref.child(&quot;Latitude&quot;).setValue(lats);
      myref.child(&quot;Longitude&quot;).setValue(longs);
  </code></pre>
  <p>I want to add these three details many times, but with different indexes.</p>
  <pre><code>    myref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot snapshot) {
              if (snapshot.exists()){
                  id = snapshot.getChildrenCount();
              }
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError error) {
  
          }
      });
  </code></pre>