views:

31

answers:

0

Hi, guys.I’ve got the following problem. I need to create interface for number selection which is similar to data selection in HTC Desire, i.e. there is an initial value which is varied by forward or backward gesture. For this I used FlipView with two TextViews. I managed to change the value by 1 unit by scrolling forward or backward. Below is my code.

class FlipGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
            if (Math.abs(e1.getX() - e2.getX()) > MAX_OFF_PATH)
                return false;                
            if(e1.getY() - e2.getY() > MIN_DISTANCE && Math.abs(velocityY) > THRESHOLD_VELOCITY) {
                for (int i = 0; i < 2500; i++)
                    viewFlipper.setInAnimation(slideTopIn);
                    viewFlipper.setOutAnimation(slideToptOut);
                    number++;  
                    if (number%2 != 0 )
                        textViewNext.setText(String.valueOf(number));
                    else
                        textViewCur.setText(String.valueOf(number));

                        viewFlipper.showNext();
                }
            else if (e2.getY() - e1.getY() > MIN_DISTANCE
                    && Math.abs(velocityY) > THRESHOLD_VELOCITY) {
                for (int i = 0; i < 2500; i++) {
                    viewFlipper.setInAnimation(slideBottomIn);
                    viewFlipper.setOutAnimation(slideBottomOut);
                    number--;
                    if (number % 2 == 0)
                        textViewCur.setText(String.valueOf(number));
                    else
                        textViewNext.setText(String.valueOf(number));
                    viewFlipper.showPrevious();
                }
            }
            } catch (Exception e) {               
        }
        return false;
    }
}   

But I failed to add inertia to make the whole process of scrolling automatic. Do you know how to resolve the problem?