开发者

Is there anyway to remove an onTouchListener from a view object?

I have an on touch listener for a webview, but it has a bad effect on the functionality of the webview, so I am wondering if there is anyway to remo开发者_运维技巧ved the on touch listener after the initial interaction?


webView.setOnTouchListener(null);


So in you activity you would set your overridden onTouchListener:

            mWebView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.setOnTouchListener(mWebView.mOnTouchListener);
                return false;
            }
        });

And you would have to make a new class, extending WebView. And within it you would define an OnTouchListener.

    public final OnTouchListener mOnTouchListener = new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent rawEvent) {
        return false;
    }
}; 

Setting the ontouchlistener to null doesn't reset it to the default definition. You still have to provide an actual listener.


I was looking for help online and got to this post. When I did

myView.setOnTouchListener(null);

my myView stopped responding to the onTouch.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜