-3

I am trying to implement a code that does something like a Joystick.

For an example when i press the LED on button, the LED stays on till i keep holding the LED on button and goes off when i release the button.

So how do i get the onRelease event when the user releases the software button.

  • If you don't want to get downvotes and unrelated answers, remove [tag: android]. – Onik Feb 25 '18 at 11:43
  • Hi Kshjit Yadav , sorry i couldn't answer your question because of some other guys marked your answer duplicate, but if you are asking this question in concern with Android Thing with Micro controller Board(Not Traditional Android Programming) then here is link, you can get your answer from here :::::::::: https://github.com/androidthings/sample-button – Ajay Rawat Mar 03 '18 at 15:50

1 Answers1

-1

Use onTouchListener with onLongPressListener. In onTouchListener look for motion_event with action_up event.

sample :

button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_UP){

        // Do what you want
        return true;
    }
    return false;
}
});
Sush
  • 3,864
  • 2
  • 17
  • 35