OnTouchListener() Problems...


Last Updated:

  1. brade

    brade Member This Topic's Starter

    Joined:
    May 11, 2010
    Messages:
    6
    Likes Received:
    0
    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

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    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 This Topic's Starter

    Joined:
    May 11, 2010
    Messages:
    6
    Likes Received:
    0
    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...