1
@Override public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { // TODO Auto-generated method stub if(arg0.getX()<arg1.getX()&&id!=0x7f020000) { previousId=id-1; imageView.setImageResource(id); id++; } else if(arg0.getX()>arg1.getX()&& id!=0x7f020004) { imageView.setImageResource(previousId); } return true; } 

The problem is when I scrolled, the id plus 2 instead 1. I don't understand why. Does someone can explain why? and how to solve it?

1
  • According to what is it being increased by 2? What kind of data is the id variable? Commented Jan 22, 2014 at 15:32

1 Answer 1

0

onScroll can be called multiple times. If you only want to increment your counter once, you should cache the floats and compare them - if they are different from the cached values, a new scroll has occurred.

Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.