Search code examples
javaandroidbuttononlongclicklistener

Do something while keeping a button pressed


I want to keep a button pressed and WHILE pressed it will do something. I firstly confused it with onLongClick() but this method will perform an action after long pressed. Tried everything but it doesn't work. Does anyone has an idea how can I achieve this?


Solution

  • You are probably looking for something more along the lines of the View.OnTouchListener

    Set the listener on your button and listen for the MotionEvent.ActionDown event found here

    kick off your code when you receive ACTION_DOWN, and stop it when your receive ACTION_UP.