1
I have an application where I use the method btprevious2.setOnTouchListener to make the page change quickly. 
btprevious2.setOnTouchListener(new View.OnTouchListener() {
            private Handler handler;
            @Override 
            public boolean onTouch(View v, MotionEvent event) {
                switch(event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        if (handler != null) return true;
                        handler = new Handler();
                        handler.postDelayed(action, 500);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (handler == null) return true;
                        handler.removeCallbacks(action);
                        handler = null;
                        break;
                }
                return false;
            }
            Runnable action = new Runnable() {
                @Override
                public void run() {
                    if(verificacao())
                    {
                        previussalve();
                        return;
                    }else{
                        if (page2>1)
                            page2--;
                        else
                            page2=60;
                        setacursor(page2);
                        escrevebotao();
                        if (page2<10)
                            pageview2.setText("0"+String.valueOf(page2));
                        else pageview2.setText(String.valueOf(page2));
                    }
                    handler.postDelayed(this, 1);
                }
            };
        });
The point is I want this to only work if another function I have to return false.
The following way below does not work, but is worth the idea
        if(!verificacao())
    {
    btprevious2.setOnTouchListener(new View.OnTouchListener() {
        private Handler handler;
        @Override 
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    if (handler != null) return true;
                    handler = new Handler();
                    handler.postDelayed(action, 500);
                    break;
                case MotionEvent.ACTION_UP:
                    if (handler == null) return true;
                    handler.removeCallbacks(action);
                    handler = null;
                    break;
            }
            return false;
        }
        Runnable action = new Runnable() {
            @Override
            public void run() {
                    if (page2>1)
                        page2--;
                    else
                        page2=60;
                    setacursor(page2);
                    escrevebotao();
                    if (page2<10)
                        pageview2.setText("0"+String.valueOf(page2));
                    else pageview2.setText(String.valueOf(page2));
                handler.postDelayed(this, 1);
            }
        };
    });
    }
How do I resolve?
In short, I just want the job btprevious2.setOnTouchListener works if my verification function returns false otherwise I want you to do nothing. 
It’s hard to understand what you want to do, but from what I understand, you have to put the condition
if (!verificacao())involving theswitch(event.getAction())that is, as soon as you enter the functiononTouch().– Paulo Roberto Rosa
paul managed to do different by blocking the action. put the if inside the run
– Joannis