Difference between setOnClickListener and setOnTouchListener?

Discussion in 'Application Development' started by Irrelephant, Sep 7, 2010.

  1. Irrelephant

    Irrelephant New Member
    5

    Sep 6, 2010
    3
    0
    5
    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
    16

    Apr 15, 2010
    17
    1
    16
    Student, Developer
    Louisiana
    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
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
    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
    5

    Sep 6, 2010
    3
    0
    5
    All right, thanks guys.
     

Share This Page

Loading...