I am making an app's which have a button to performed an action, but i want to perform the action when user long press on the button.Since Google provides the long press time duration appx .5 sec but I want to customize this time duration. Please help...
You can try Touch Listener
to do this.
Try:
Handler handler = new Handler();
b.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
handler.postDelayed(run, 5000/* OR the amount of time you want */);
break;
case MotionEvent.ACTION_CANCEL:
handler.removeCallbacks(run);
break;
case MotionEvent.ACTION_UP:
handler.removeCallbacks(run);
break;
}
return true;
}
});
Where b
is the view
on which you want to make long click.
And Runnable
run
is as follows
Runnable run = new Runnable() {
@Override
public void run() {
// Your code to run on long click
}
};
Hope it helps... :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With