Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

android - onLongClickListener does not work on WebView

I have the following struktur to implement an longclicklistener. It works if I click on a text on the webview which contains a html-link, so I know the structure is not completely wrong.

I removed this link now and the listener just doesn't listen to clicks anymore. Does anybody know this problem and have some advices?

    private View.OnLongClickListener mLongClickHandler = new View.OnLongClickListener()   {
    @Override
    public boolean onLongClick(View view) {
        ...
        return true;
    }
};

...

mywebview.setOnLongClickListener(mLongClickHandler);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I tried now to clone the longclick action by myself. This works but only a few times. After a certain time, the onTouch-Event is not called anymore... Suggestions?

private Runnable copyTextAfterDelay=new Runnable() {
    public void run() {
        ...
    }
};

...

        myWebView.setOnTouchListener(new View.OnTouchListener() { 
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) { 
                    case MotionEvent.ACTION_DOWN:  
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        mTimerHandler.postDelayed(copyTextAfterDelay,1000);
                        break;
                    case MotionEvent.ACTION_UP: 
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        break;
                }
                return false;                  
            }
            });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...