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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:49+00:00 2026-05-25T18:58:49+00:00

I have a question thta keeps occuring and i was wondering how to fix

  • 0

I have a question thta keeps occuring and i was wondering how to fix it. I want to be able to interact with views, in this case specifically the webview from outside the oncreate so that my methods can interact with the webview defined in the oncreate.

Here is an example of what im trying to do. In the search voice array im checked to see if the user said “go” and if they did i want either the go button to be pressed or to simply execute the code that the go button would do. I hope i explained this well enough, if you need clarification please let me know, thanks in advance!

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class web extends Activity {
    static final int check = 111;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);
        final WebView webBrowser = (WebView) findViewById(R.id.webview);
        webBrowser.setWebViewClient(new cpViewClient());
        webBrowser.getSettings().setJavaScriptEnabled(true);
        webBrowser.getSettings().setLoadWithOverviewMode(true);
        webBrowser.getSettings().setUseWideViewPort(true);
        webBrowser.loadUrl("http://www.google.com");
        final InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

        Button bGo = (Button) findViewById(R.id.go);
        Button bBack = (Button) findViewById(R.id.back);
        Button bForward = (Button) findViewById(R.id.forward);
        Button bRefresh = (Button) findViewById(R.id.refresh);
        Button bClearHistory = (Button) findViewById(R.id.clearhistory);
        final EditText etUrl = (EditText) findViewById(R.id.url);

        bGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String enteredUrl = etUrl.getText().toString();
                enteredUrl = enteredUrl.toLowerCase();
                int len = enteredUrl.length();
                /*
                 * if (enteredUrl.substring(0, 3).equals("www")) enteredUrl =
                 * "http://" + enteredUrl; else if (enteredUrl.substring(0,
                 * 11).equals("http://www.")) //Do nothing its perfect
                 * Log.d("URL", "The Url is fine"); else enteredUrl =
                 * "http://www." + enteredUrl;
                 * 
                 * String dot1 = enteredUrl.substring(len-5, len-4); String dot2
                 * = enteredUrl.substring(len-4, len-3); if (!dot1.equals(".")
                 * || !dot2.equals(".")) enteredUrl = enteredUrl + ".com";
                 */
                if (enteredUrl.indexOf("http://") == -1
                        & enteredUrl.indexOf("www.") == -1) {
                    enteredUrl = "http://www." + enteredUrl;
                } else if (enteredUrl.indexOf("http://") == -1) {
                    enteredUrl = "http://" + enteredUrl;
                }

                if (enteredUrl.indexOf(".com") == -1
                        & enteredUrl.indexOf(".org") == -1
                        & enteredUrl.indexOf(".net") == -1
                        & enteredUrl.indexOf(".mil") == -1
                        & enteredUrl.indexOf(".gov") == -1
                        & enteredUrl.indexOf(".edu") == -1
                        & enteredUrl.indexOf(".info") == -1) {
                    enteredUrl = enteredUrl + ".com";
                }

                webBrowser.loadUrl(enteredUrl);
                etUrl.setText(enteredUrl);
                imm.hideSoftInputFromWindow(etUrl.getWindowToken(), 0);
            }

        });
        bBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (webBrowser.canGoBack())
                    webBrowser.goBack();
            }

        });
        bForward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (webBrowser.canGoForward())
                    webBrowser.goForward();
            }

        });
        bRefresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                webBrowser.reload();
            }

        });
        bClearHistory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                webBrowser.clearHistory();
            }

        });
        Button VR = (Button) findViewById(R.id.webvoice);
        VR.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                getvoice();
            }

        });



    }
    public void getvoice() {
        Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        startActivityForResult(i, check);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (requestCode == check && resultCode == RESULT_OK) {
            result = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            final TextView tvvoicearray = (TextView) findViewById(R.id.tvvoicearray);
            tvvoicearray.setText(result.get(0));
            searchvoicearray();
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    public void searchvoicearray() {
        // Log.d("DEBUGGINGG",result.get(0));
        // System.out.println(result);
        int size = result.size();
        int i = 0;
        while (i < size) {
            String s = result.get(i);
            // next line removes all spaces in the string
            // s= s.replaceAll(" ", "");
            if (s.indexOf("go") != -1 ) {
                i = size;
                //i want the button go to be pressed or its action to be completed.

                if (webBrowser.canGoBack())
                webBrowser.goBack();
            } 

            else if (s.indexOf("back") != -1) {
                i = size;
                if (webBrowser.canGoBack())
                    webBrowser.goBack();
            } 

            else {
                System.out.println(result.get(i) + " is not internet");
                Log.d("DEBUGGINGG", result.get(i) + " is not internet");
                // }
                i++;
            }
        }

    }

    ArrayList<String> result = new ArrayList<String>();

}
  • 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-25T18:58:49+00:00Added an answer on May 25, 2026 at 6:58 pm

    Then, declare webview outside onCreate:

    static final int check = 111;
    private WebView webBrowser;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);
        webBrowser = (WebView) findViewById(R.id.webview);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question to Java or C# programmers. I want to render some pages
I have question with this same title here but now as I'll present in
i have question for example i want to implement binary tree with array i
I have question about integrate Open office with PHP. I want make mail merge
I have question regarding polymorphism about its assignment statement, for Example this is The
I have a question regarding inheritance in Java. If I have this base class
ok i have question, i made this code to play axmediaplayer base on item
I have question for you ... I have UITableView and I want to catch
I have question on controlling the amount of concurrent threads I want running. Let
I have question about python and sqlite3. I want to drop a table from

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.