Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:40:55+00:00 2026-06-14T05:40:55+00:00

I have a WebView that is displaying a local HTML page within the assets

  • 0

I have a WebView that is displaying a local HTML page within the assets folder. The WebView is part of larger layout in an Activity. I’m trying to allow users to drag text from an EditText widget to an Input Element within the WebView. Everything works good except for converting the screen coordinates received by the drag listener to the screen coordinates used by document.elementFromPoint. They don’t match up. It’ll keep dropping text into input boxes which are further down then the users finger. Any help would be appreciated. Warning: my javascript knowledge is pretty pathetic.

Basic flow:

  1. WebView’s onDrag event catches the ACTION_DROP event.
  2. The event’s x, y location is passed to a Javascript function
  3. The Javascript function finds element based on points and updates the value

In my Activity:

private class OnWebViewDragListener implements OnDragListener {
    public boolean onDrag(View v, DragEvent event) {
        switch (event.getAction()) {
            case DragEvent.ACTION_DROP:
                String dropText = event.getClipData().getItemAt(0).getText().toString();
                mJavaScript._dropText(mWebView, dropText, event.getX(), event.getY());
                return true;

            default:
                break;
        }

        return false;
    }
}

Javascript wrapper:

public void _dropText(WebView wv, String text, float x, float y) {
    wv.loadUrl("javascript:dropText('" + text + "', " + x + ", " + y + ")");
}

Javascript function:

<script type="text/javascript">
function dropText(text, x, y) {
    var elem = document.elementFromPoint(x, y);

    if (elem.tagName == "INPUT") {
        elem.value = text;
    }
}
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:40:57+00:00Added an answer on June 14, 2026 at 5:40 am

    Figured it out. Was making the conversion more complicated then what it needed to be. Both Android’s WebView and the WebPage have their own coordinate system based on the size of their visible view port. Yes both report different sized view ports. Even though both view ports can be scrolled, there’s no need to include those scrolled changes. The simple formula:

    DE = DragEvent
    WV = WebView

    x = DE.getX() * (window.innerWidth / WV.getWidth());
    y = DE.getY() * (window.innerHeight / WV.getHeight());

    How my code looks now:

    In Activity:

    private class OnWebViewDragListener implements OnDragListener {
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
                case DragEvent.ACTION_DROP:
                    String dropText = event.getClipData().getItemAt(0).getText().toString();
                    mJavaScript._dropText(mWebView, dropText, event.getX(), event.getY());
                    return true;
    
                default:
                    break;
            }
    
            return false;
        }
    }
    

    Javascript wrapper:

    public void _dropText(WebView wv, String text, float x, float y) {
        wv.loadUrl("javascript:dropText('" + text + "', " + x + ", " + y + ", " + wv.getHeight()
                + ", " + wv.getWidth() + ")");
    }
    

    Javascript function:

    <script type="text/javascript">
    function dropText(text, x, y, height, width) {
        x *= (window.innerWidth / width);
        y *= (window.innerHeight / height);
    
        var elem = document.elementFromPoint(x, y);
    
        if (elem.tagName == "INPUT") {
            elem.value = text;
        }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which is displaying a web page using a WebView. Within
On Android, I have a WebView that is displaying a page. How do I
I have a webview that displaying authenticated web page. I need to save the
I have a webview that's supposed to show cyrillic text wv.loadData( myStringHtml, html/text, utf-8);
I have a webview that I'm creating in an Activity which is a child
I have a webview that has some custom HTML loaded into it. In this
I have a WebView that is loading a page from the Internet. I want
In my app I have a webview that is used solely for displaying the
I have one webview that fits fullscreen and loads an html file. Then another
I have an app that is displaying a webpage using a WebView control. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.