jack daniels
jack daniels

Reputation: 19

Viewflipper not flipping

I am creating a Viewflipper. However when i run and try to move my hand on the screen, nothing happens. What am i Missing out? Thanks

Here is the java code.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery);

    flipper = (ViewFlipper)findViewById(R.id.flipperGallery);
    flipper.setOnTouchListener((android.view.View.OnTouchListener) this);
}

@Override
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction())
{
    case MotionEvent.ACTION_DOWN:
    {
    lastX = touchevent.getX();
    Toast.makeText(this, "X: " + lastX, Toast.LENGTH_LONG).show();

    break;
    }
case MotionEvent.ACTION_UP:
    {
    float currentX = touchevent.getX();
    if (lastX < currentX){
        Toast.makeText(this, "scroll right: ", Toast.LENGTH_LONG).show();

        if (flipper.getDisplayedChild()==0) break;
        flipper.setInAnimation(this, R.anim.in_from_left);
        flipper.setOutAnimation(this, R.anim.out_to_right);
        flipper.showNext();
        }
    if (lastX > currentX){
        Toast.makeText(this, "scroll left: ", Toast.LENGTH_LONG).show();

        if (flipper.getDisplayedChild()==1) break;
        flipper.setInAnimation(this, R.anim.in_from_right);
        flipper.setOutAnimation(R.anim.out_to_left);
        flipper.showPrevious();
        }
    break;
    }
}
return false;
}

I am creating a Viewflipper. However when i run and try to move my hand on the screen, nothing happens. What am i Missing out? Thanks

Upvotes: 1

Views: 124

Answers (1)

justHooman
justHooman

Reputation: 3054

When you receive ACTION_DOWN in onTouchEvent and return false you do not receive any further event such as ACTION_UP, ...
try this :

case MotionEvent.ACTION_DOWN:
{
lastX = touchevent.getX();
Toast.makeText(this, "X: " + lastX, Toast.LENGTH_LONG).show();

return true;
}

Upvotes: 1

Related Questions