Difference between setOnClickListener and setOnTouchListener?


Last Updated:

  1. Irrelephant

    Irrelephant New Member This Topic's Starter

    Joined:
    Sep 6, 2010
    Messages:
    3
    Likes Received:
    0
    This might be a dumb question. I don't own any phone with the Android OS so there's no way for me to test this, but I figured since they're touchscreen I would use setOnTouchListener, but at the same time, setOnClickListener seems to make sense. Can I use either one?
     

    Advertisement
  2. SWhite

    SWhite Member

    Joined:
    Apr 15, 2010
    Messages:
    17
    Likes Received:
    1
    There is a subtle difference.

    onTouch gives you a chance for something to respond before the view does.
    onClick is fired after the view responds

    in case you dont know of this heres the complete Android API
    Package Index | Android Developers
     
    Irrelephant likes this.
  3. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    If you just want to handle a tap on the screen you should use the onClickListener because some phones might not have touch and the onClickListener also reacts to the normal button press.
     
    Irrelephant likes this.
  4. Irrelephant

    Irrelephant New Member This Topic's Starter

    Joined:
    Sep 6, 2010
    Messages:
    3
    Likes Received:
    0
    All right, thanks guys.
     

Share This Page

Loading...