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 6715927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:40:21+00:00 2026-05-26T08:40:21+00:00

In my Android web app I am trying to use javascript (from a remote

  • 0

In my Android web app I am trying to use javascript (from a remote HTML file) to control the visibility of an Android WebView.

I have attempted to use the addJavascriptInterface class with no success. (see http://developer.android.com/guide/webapps/webview.html)

Essentially I would like my javascript to be the following

<script>
function this() {
  Android.hideView('myWebViewID');
}
window.onload = this;
</script>

Seems like it would be easy, yet all my attempts cause my app to crash during debugging.

My latest attempt was something along these lines:

public class JavaScriptInterface {
    Context mContext;
    JavaScriptInterface(Context c) {
        mContext = c;
    }
    public void hideView(View v) {
        WebView webview_x = (WebView) v;
        webview_x.setVisibility(View.GONE);
    }
}
  • 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-05-26T08:40:21+00:00Added an answer on May 26, 2026 at 8:40 am

    The problem is that you are casting the string “myWebViewID” in a WebView object.
    I guess this is impossible.

    To do what you want, you have to implement something like a switch that convert the string you use in JS to an ID (int) that identifies your WebView:

    public class JavaScriptInterface {
        private Activity mContext;
    
        JavaScriptInterface(Activity c) {
            mContext = c;
        }
    
        public void hideView(String v) {
            int id = stringToId(v);
            WebView webview_x = (WebView) mContext.findViewById(id);
            webview_x.setVisibility(View.GONE);
        }
    
        private Integer stringToId(String str) {
            if(str.equals("stringForId1") {
                return R.id.webView1;
            } else if(str.equals("stringForId2") {
                return R.id.webView2;
            } else if(...) {
              ....
            } else {
                return null;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to pull information from a web page for use in a Android app.
I'm building an Android app. I'm trying to use Admob, but I have some
We have an Android app and a Web Service. We want to download part
I'm trying to authenticate to a web server from an android class with the
I am trying to write an Android app to connect to an existing web
I am requesting information from a web service in my android app. The web
I have an Android app that talks to .net web service via http over
I'm trying to call a RESTful web service from an Android application using the
From my android app, I'm downloading an apk from the web, storing it in
I am trying to get my android webview app to open tel: links to

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.