• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Webview open as new screen

Hi Folks,

Ive been searching for a while (here, in other forums, and good ol' google), but i cant find a solution.

My goal is this, to have a button click open a webview and display embedded HTML.
Ive got a button press to show a 'toast' pop-up, so i know where to hook the code to open the webview.

when I try to set up the web view with :
Code:
WebView webview = new WebView(this);

I get this error:
Code:
The constructor WebView(new View.OnClickListener(){}) is undefined

Any help appreciated,
GIR
 
It's a java thing actually. The 'this' keyword refers to a new scope which you create by nesting.

example:
Code:
// start of scope 1
class Foo {

   int x = 0;

   public Foo {
      this.x = 3 // this works because this refers to scope 1

      // start of scope 2
      buttonx.setOnClickListener(new OnClickListener() {
         
         // this is a nested class

         public void onClick() {
            this.x = 3 // this wil fail since x is not in this scope.

            // a new class scope is define by the new OnClickListener() {}
            // the 'this' keyword will refer to the OnClickListener() {}
         }

      });
   }
}

I hope this explains enough.
 
  • Like
Reactions: GIR
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones