I've made something similar, but in my case I wanted to show a new activity if the button was pressed continuously for 3 seconds. Use this code for reference.
Runnable mRunnable,timeRunnable;
Handler mHandler=new Handler();
btnBackoffice = (Button) findViewById(R.id.btn_backoffice);
btnBackoffice.setOnTouchListener(buttonOnTouchListener);
private OnTouchListener buttonOnTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch ( event.getAction() ) {
case MotionEvent.ACTION_DOWN:
mHandler.postDelayed(timeRunnable, 3000);
break;
case MotionEvent.ACTION_UP:
mHandler.removeCallbacks(timeRunnable);
break;
}
return true;
}
};
timeRunnable=new Runnable(){
@Override
public void run() {
Intent intent = new Intent(MainActivity.this, BackofficeActivity.class);
startActivity(intent);
}
};
Hope it helps.