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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:38:58+00:00 2026-06-12T02:38:58+00:00

exi want to load an url in mywebview when the end-user click on ‘item1’

  • 0

exi want to load an url in mywebview when the end-user click on ‘item1’ in the option menu

Here is my code :

package com.exemple.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
import android.app.AlertDialog;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView myWebView = (WebView) findViewById(R.id.webview);
        myWebView.setWebViewClient(new WebViewClient());
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("http://m.google.com");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.item1:
                //AlertDialog alertDialog = new AlertDialog.Builder(this).create();
                //alertDialog.setTitle("Reset...");
                //alertDialog.setMessage("Are you sure?");
                //alertDialog.show();
                myWebView.loadUrl("http://m.google.com");
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

Thanks !

  • 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-12T02:38:59+00:00Added an answer on June 12, 2026 at 2:38 am

    Just change

    WebView myWebView = (WebView) findViewById(R.id.webview);
    

    to

    myWebView = (WebView) findViewById(R.id.webview);
    

    And add the following as a class variable:

    WebView myWebView;
    

    So your final code becomes:

    public class MainActivity extends Activity {
    
        WebView myWebView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            myWebView = (WebView) findViewById(R.id.webview);
            myWebView.setWebViewClient(new WebViewClient());
            WebSettings webSettings = myWebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            myWebView.loadUrl("http://m.google.info"); //You may want to comment this out, as you said you wanted to load it only when the user clicked
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle item selection
            switch (item.getItemId()) {
                case R.id.item1:
                    //AlertDialog alertDialog = new AlertDialog.Builder(this).create();
                    //alertDialog.setTitle("Reset...");
                    //alertDialog.setMessage("Are you sure?");
                    //alertDialog.show();
                    myWebView.loadUrl("http://m.google.com");
                    return true;
                default:
                    return super.onOptionsItemSelected(item);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following string hello[code:1], world [code:2], hello world I want to replace this
Here's my code: public class Game extends JComponent implements Runnable { World w =
I want to split List of user generic List into its small list with
I'm working on building my own base user interface classes. On them, I want
I want to put code that i generate automatically and new classes in different
ex: i want to clean the script tag , but i want to keep
like this question I want to pass a function with arguments. But I want
In my asp.net I am using Datalist in that I want to limit row
I am creating ASP.NET textbox controls dynamically. I want to know the difference between
I have a RadioGroup and two RadioButtonField added in a VerticalFieldManager. I want put

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.