'How to auto increment on a specific child on firebase based another data

I am using a Firebase Realtime database. I want to increment a number every time I create a data. However, I want to base it from another data. Example Year is 2000 then it will 2000-1. Then another data is 2000 it will be 2000-2. Then if the year is 2001 it will be 2001-1 since it is a different year. I want to increment the numbers. However, I want the number to restart if it has another year.

idReg: 1

idYear: 2000

newDate: September 16, 2000

    etIdYear.setEnabled(true);
    setNewIdYear = newDate.substring(newDate.length() - 4);
    etIdYear.setText(setNewIdYear);
    newIdYear = Integer.parseInt(setNewIdYear);
    newIdReg = Integer.parseInt(setNewReg);

    mCustom = new Custom(newIdYear, newIdReg, newDate);

    key = mDatabase.child("Custom").push().getKey();
    mDatabase.child(newDate).setValue(mCustom);

I am still new to this, thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source