Android: ZoomPicker breaks onTouchListener?

This is the closest I could come to a solution to this problem. I needed to set the input focus to the WebView whenever it was touched. The only way I could do it was by extending WebView and overriding the onTouchEvent function.

This function gets called even after Zooming is used in the WebView public class NewWebView extends WebView { public NewWebView(Context context) { super(context); } public NewWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public NewWebView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onTouchEvent(MotionEvent ev) { boolean consumed = super. OnTouchEvent(ev); if (isClickable()) if (ev.getAction() == MotionEvent. ACTION_DOWN) { if (!hasFocus()) requestFocus(); } return consumed; } Don't forget that if you use XML to create your layout, you'll need to change "WebView" to your fully qualified packagename.

NewWebView (otherwise you get a confusing ClassCastException if you try to do something like: webView = (NewWebView) findViewById(R.id. New_web_view).

This is the closest I could come to a solution to this problem. I needed to set the input focus to the WebView whenever it was touched. The only way I could do it was by extending WebView and overriding the onTouchEvent function.

This function gets called even after Zooming is used in the WebView. Public class NewWebView extends WebView { public NewWebView(Context context) { super(context); } public NewWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public NewWebView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onTouchEvent(MotionEvent ev) { boolean consumed = super. OnTouchEvent(ev); if (isClickable()) if (ev.getAction() == MotionEvent.

ACTION_DOWN) { if (!hasFocus()) requestFocus(); } return consumed; } Don't forget that if you use XML to create your layout, you'll need to change "WebView" to your fully qualified packagename. NewWebView (otherwise you get a confusing ClassCastException if you try to do something like: webView = (NewWebView) findViewById(R.id. New_web_view).

Sorry for not getting around to it earlier, but I finally had a chance to test this code, unfortunately this method does not get onTouch working again – tabjsina Feb 21 at 3:30 It didn't work for me either. – Lorne Laliberte Sep 26 at 21:28.

I had the same problem, but managed to solve it by setting the listener again in my extended WebView class: public void invalidate() { super.invalidate(); setOnTouchListener(this); } Unfortunately, now I have the opposite problem in that the zoom controls (the plus/minus widget) does no longer receive touch events. There seems to be some exclusivity between having an OnTouchListener and zoom, at least in Android SDK level 8 (Froyo 2.2). This sounds like a bug to me, but would love to find a workaround.

But I really need to get them working together.

A dirty solution is to cover an invisible view on top of your web view and detects touches there, and you have to distinguish if the touch is consumed, or return false to pass touches to underlying web view.

The workaround is pretty simple. You have to create a custom class, that extends one of the ViewGroup subclasses like LinearLayout. Then override onInterceptTouchEvent - it will be called prior to ViewGroup child's onTouchEvent.It is not very elegant to put a webview control into your custom ViewGroup subclass, and then insert it into activity's view hierarchy - where it is desired, but - it works.

Private class OwnedLayout extends LinearLayout { protected OwnedLayout(Context context, AttributeSet attrs) { super(context, attrs); } protected OwnedLayout(Context context) { super(context); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { //Put Your code here return super. OnInterceptTouchEvent(ev); } }.

I had a similar problem where onTouch wouldn't get called after I used pinch to zoom. Inspired by jpeskin's answer, this code worked for me (add it in the class that extends WebView): @Override public boolean onTouchEvent(MotionEvent event) { boolean consumed = super. OnTouchEvent(event); onTouch(this, event); return consumed; } update: @Override public boolean onTouch(View v, MotionEvent event) { return touchListener.

OnTouch(v, event); } The touchListener is of the type android.view.View.OnTouchListener.

Your code doesn't compile for me in a class extending WebView -- it says the onTouch method is undefined. Did you implement an onTouch method in the WebView subclass yourself? If so your example would be clearer with a comment in place of the onTouch() call.

– Lorne Laliberte Sep 26 at 16:36 I've checked it and I have indeed a onTouch() method in the class extending WebView, so the class implements OnTouchListener. – Stijn. V Sep 27 at 7:05.

In my android app I have a ViewFlipper that contains some LinearLayout. On every LinearLayout I have a ImageView.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions