i have a button in android.If i hold the button a message should go and while releasing another message should go but Sometimes still holding a button also release is happening and release message is going.
Here is my code for button:-
open_curtain.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
v.setSelected(true);
DeviceDataClassTwo obj = (DeviceDataClassTwo) v.getTag();
new ButtonOPressed(obj).execute();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
//it comes here when i move my finger more then 100 pixels
v.setSelected(false);
obj = (DeviceDataClassTwo) v.getTag();
new ButtonORelease(obj).execute();
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(140);
break;
}
return true;
}
});