• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps OnTouchListener() Problems...

brade

Lurker
When I first created my GUI "buttons" I set OnClickListeners for each of them. When I ran the app on my actual phone, I didn't like how the action was performed when the user "releases" the button, instead of acting immeadiately upon pressing. So I switched to OnTouchListeners. The problem that I am having now is that as long as I hold the button down it performs the action over and over, when I only want it to happen once. Any Ideas?

Heres one of my OnTouchListener segments:

button01.setOnTouchListener(​
new View.OnTouchListener()
{
@Override

public boolean onTouch(View v, MotionEvent event)
{
if(check)
{
vibe.vibrate(vib);
SwitchIt(1);
moves++;
DrawIt();
IsClear();
check = false;
return true;
}
check = true;
return true;
}

});
 
Are all the motion events ActionDown? I think you're probably getting a lot of ActionMoves which you can filter out. If it is sending a bunch of actionDowns you can try having a flag that resets when you receive an actionUp

You could also try ontouchevent instead.
 
That was exactly the problem. Since i easnt specifying a single event, EVERY event was trigerring my OnTouch function... thank you!
 
Back
Top Bottom