1. Download our Official Android App: Forums for Android!

Apps Difference between setOnClickListener and setOnTouchListener?

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

  1. Irrelephant

    Irrelephant Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 6, 2010

    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 Newbie
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    Apr 15, 2010

    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
    Rank:
    None
    Points:
    38
    Posts:
    142
    Joined:
    Apr 20, 2010

    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 6, 2010

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

Share This Page

Loading...