Jesse
Jesse

Reputation: 1

Need help with android WebView

I am new to Android and java development. I create a WebView object in the OnCreate function. Now I need to be able to pass this same object to other functions in the code, such as the onOptionsItemSelected function. I currently have it where I just create a new WebView object in each function where I need it, but this slows down the code since it has to recreate it and such.

Upvotes: 0

Views: 419

Answers (1)

RichieHindle
RichieHindle

Reputation: 281735

Something as simple as this?

public class MyActivity extends Activity {

    WebView wv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        wv = new WebView(this);
        setContentView(wv);

    @Override
    public boolean onOptionsItemSelected(MenuItem  item){
        wv.doSomething();
    }

Upvotes: 1

Related Questions