views:

182

answers:

1

I can detect a long click on my WebView using the following code:

webView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Log.d("Debug","On Long Press Web View");
            return false;
        }
    });

This works fine when i long press on a link, but doesnt work when I long press in an area where no link is, i.e whitespace.

My first thought to address this was to use the GestureDetector:

public boolean dispatchTouchEvent(MotionEvent event) {              
    super.dispatchTouchEvent(event);
    return detector.onTouchEvent(event);
}

or

public OnTouchListener otl = new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (detector.onTouchEvent(event)){
            return true;
        }else{
            return false;
        }
    }
};

And then overide the onLongPress method of the GestureDetector:

public void onLongPress(MotionEvent e) {

}

Either of the above methods above work and the onLongPress method is executed when I long click on the web page but not on a link. The problem is when I now long click on a link both long press methods are called, firstly the GestureDetector onLongPress and secondlythe WebView onLongClick. Is there a way to just invoke only the WebView onLongClick() when i long click on a link.

Andy

A: 

I got the exact same problem! See here

But I haven't found a workaround yet

Arman