Q:

Pasting text into a webview

in the default android browser, when you long-press on a textbox inside of a webpage you get a context menu showing several options, such as the ability to paste text into the textbox. How do I replicate this functionality with my own webview?
I looked in the android source code, specifically the code that handles context menu creation and found this:
     @Override
     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

         ...

         WebView.HitTestResult result = webview.getHitTestResult();
         int type = result.getType();
         if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
             // let TextView handles context menu
             return;
         }

         ...

    }

What the code means is that when the user long-presses on a "EDIT_TEXT_TYPE" ie. a textbox, the webview does nothing. Some magical "TextView" handles the context menu. Now I'm lost, how do I get this context menu to appear in my webview?

A:

Have you tried using registerForContextMenu().  I know it works on ListView for sure but it also works on other views.
It should go something like this:
registerForContextMenu(yourWebView);

@Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

       //Code for "Paste";

     }

Hope this helps!

