1. Check out our app, Forums for Android! Download and leave feedback here!

OnTouchListener() Problems...

Discussion in 'Application Development' started by brade, Jul 11, 2010.

  1. brade

    brade Member
    Thread Starter
    5

    May 11, 2010
    6
    0
    5
    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;
    }

    });
     

    Advertisement

  2. cp1

    cp1 Well-Known Member
    53

    Apr 30, 2010
    375
    35
    53
    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.
     
    brade likes this.
  3. brade

    brade Member
    Thread Starter
    5

    May 11, 2010
    6
    0
    5
    That was exactly the problem. Since i easnt specifying a single event, EVERY event was trigerring my OnTouch function... thank you!
     

Share This Page

Loading...