I am creating an application, but I am not able to do the following: I have a button that increments a variable and a button that decrements and saves the value in the database through php and shows in a textview. What I am trying to do is that when the increment (or decrement) button receives multiple clicks, it will save only the last incremental value. Example:
btn_UP.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
if (temperature <32)
temperature ++;
txtTemp.setText ("" + temperature);
}
}
});
btn_DOWN.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
if (temperature> 17)
temperature--;
txtTemp.setText ("" + temperature);
}
}
});
This way I'm doing it, it increases and decreases with each click made in the button, but when receiving multiple clicks, it also does the same, however I would like it to continue incrementing and only when the multicliques finishes that the value was displayed and saved in the database.
I tried to do the following and it did not work as expected:
public class Activity ... {
private long mLastClickTime = 0;
protected void OnCreate ... {
btn_tempUP.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
if (SystemClock.elapsedRealtime () - mLastClickTime <500) {
return;
}
mLastClickTime = SystemClock.elapsedRealtime ();
if (temperature <32)
temperature ++;
txtTemp.setText ("" + temperature);
}
}
});
}
}
Can someone help me with how to do this? If I could be clear.