Max McKinney
Max McKinney

Reputation: 1218

Is there some kinda onClickDownListener/onClickUpListener?

I've been trying to figure out a way to check if a button and/or image is being pressed. But I need to do different things depending if it's being pressed, or not pressed. Here's an example; A player holds down a fire button, the character continues to fire until the button is lifted. How would I go about doing this? Thanks for your time, so if my question is to vague.

Upvotes: 0

Views: 39

Answers (1)

serkanozel
serkanozel

Reputation: 2927

You can just set an OnTouchListener:

ImageView myView = (ImageView)findViewById(R.id.my_image_view);         
myView.setOnTouchListener(new View.OnTouchListener(){
    public boolean onTouch(View v, MotionEvent event){
        if (event.getAction() == MotionEvent.ACTION_DOWN){
            // do here what ought to happen until the finger is lifted
        }else if(event.getAction() == MotionEvent.ACTION_UP){
            // stop the action because the finger is lifted
        }
    }
});

Hope this helps,

-serkan

Upvotes: 3

Related Questions