Reputation: 459
as the documentation for TouchGesture says as follows:
Capturing touch events for a single view
As an alternative to onTouchEvent(), you can attach an View.OnTouchListener object to any View object using the setOnTouchListener() method. This makes it possible to to listen for touch events without subclassing an existing View. For example:
View myView = findViewById(R.id.my_view);
myView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// ... Respond to touch events
return true;
}
});
Beware of creating a listener that returns false for the ACTION_DOWN event. If you do this, the listener will not be called for the subsequent ACTION_MOVE and ACTION_UP string of events. This is because ACTION_DOWN is the starting point for all touch events.
But returning false for the onTouch() method calls subsequent events ACTION_MOVE AND ACTION_UP and returning true is not calling the following events such as ACTION_MOVE AND ACTION_CANCEL. This look counter part from the documentation.
my code :
/**
* Setting Touch Listener to Tabs <br/>
* ReSelecting the tabs calls the touch listener and open the Default/Initial Screen for the tab.
*/
protected void setTabListeners() {
if (mTabHelper.getTabHost() != null) {
final TabWidget tabWidget = mTabHelper.getTabHost().getTabWidget();
int tabsCount = tabWidget.getChildCount();
for (int i = 0; i < tabsCount; i++) {
mLogger.info("count = " + i);
tabWidget.getChildAt(i).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mLogger.info("event "+event.getAction());
return false;
}
});
}
}
Upvotes: 0
Views: 10628
Reputation: 7752
Returning false means that you won't have consumed the event and it's up for grabs by anything else along the chain.
I would recommend that you take the time to watch the talk by Dave Smith on how touch events work on Android and how they are passed down through to child views to consume the events. It's actually the inverse of what most people would expect. This should clear up any other questions you have.
Upvotes: 2