0

The first click in the button was has been already subtracted. For example the value inside the button is 3 it became 2 after clicking. How to reduce value in every click you made in the button?

String uid = Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();
    databaseReference = FirebaseDatabase.getInstance().getReference();
    uidRefItem = databaseReference.child("UserItem").child(uid);

Here inside of the button.

uidRefItem.child("TimerAddOnemin").setValue(getTimerAdd - 1);

On my second click the value on database didn't update only on first click.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84

1 Answers1

1

Make sure to use:

      addValueEventListener()

Instead of :

     addListenerForSingleValueEvent()

for more info check :Difference between addValueEventListener() and addListenerForSingleValueEvent() of firebase

  • `addValueEventListener()` yup already use it. then I use this part `.setValue(ServerValue.increment(-1));` to continuously subtract on button click – Albert Pasco Aug 27 '21 at 04:45