0

I have a short question. Should I use in same time OnTouch and OnClick listeners ? If I`m correct one is for touch screens and other is for devices with out it. Am I wrong ? If not should I use both listeners to secure both kind of devices ?

Fixus
  • 4,631
  • 10
  • 38
  • 67

2 Answers2

2

You only need OnTouch if you have some event that should only happen with a touch screen. If you just want to do something when the user taps (or clicks), then you only need OnClick.

DeeV
  • 35,865
  • 9
  • 108
  • 95
  • ok but what if I want do most flexible app ? If I have simple list it should be usable on touch and nontouch screen. So should I use then both or should I make app for touch only and non touch only ? – Fixus Jul 01 '11 at 21:16
  • OnClick works for both. If you do the same action for both types of events, then you only need to implement OnClick. If you, for some reason, only want a specific action to occur when the user touches the view, then you must implement OnTouch. – DeeV Jul 01 '11 at 21:23
  • Thank you very much :) Now I get in 100% :) – Fixus Jul 01 '11 at 21:27
1

I use both. I've create a class extending from Button class. I've put my custom appearance and interaction (programmaticaly) on the onTouch() method and the functionality for the onClick().

benqus
  • 1,119
  • 2
  • 10
  • 24
  • Do you get some exta features from using both ? – Fixus Jul 02 '11 at 12:47
  • Yes, I do functionality on onClick() and drawing (invalidating/redrawing) the element on the onTouch(). Good way to separate what should the compnent do and how should it look like. =] – benqus Jul 13 '11 at 15:28