Frage

@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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top