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.
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
精彩评论