saurabh pandey saurabh pandey - 11 months ago 29
Java Question

I wanna perform back & forth functionality animation, I've used odd & even click counts but it stops after 1st cycle

//Initializing clickCount
int clickCount = 0;
public void animateButton(View view) {

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickCount++;
if(clickCount%2==0 && clickCount==0){ //clickCount=0 declared in global variable
button.animate().translationX(400);
}
else {
button.animate().translationX(-400);
}
}
});


Or you can suggest any other method too.

Answer Source

Your if statement is true only once, at initialization. Afterwards clickCount is 1,2,3,... which is clickCount==0 : False so the if statement is also false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download