I have an application where I use the btprevious2.setOnTouchListener
method to perform quick page switching.
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 question is do I want this to only work if another function that I have return false.
The following mode below does not work, but 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 solve it?
In short, I just want the btprevious2.setOnTouchListener
function to work if my check function returns false otherwise I want you to do nothing.