开发者

Android touch listeners?

I need to nest s few touch listeners. For example I have a ViewGroup that will have the following listeners: onItemClick, onLongItemClick and onTouch.EV == move.

The items inside the view group will have an onClick as well.

In my tests both sets of listeners work independently, but not interdependently. Is th开发者_运维技巧ere any way I can interlink the listener groups?

Thanks, ~Aedon


i´m not sure, but maybe you can dispatch the touch event from the root view to its child view (starting with the activity)

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (ChildView.dispatchTouchEvent(event))
        return true;
    else
        return false;
}

after the user clicked the button, dispatch the touch event back to the root view.


All events are propagated from root to child views. If a view does not want to handle a event it passes it to its child views. If a view consumes a event such a click on a ViewGroup, you can either let it trickle down or block it. Usually returning false from event callback indicates the event was not handled, and returning true indicates event was handled and will not be given to any other views.

Say you have a button in a ViewGroup. If you press the button, the ViewGroup will receive the event first, it can chose to not to pass the event to its children, in which case the button will not respond to the click.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜