开发者

Is there some kinda onClickDownListener/onClickUpListener?

开发者 https://www.devze.com 2023-04-10 12:06 出处:网络
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;

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号