Webview open as new screen

Discussion in 'Application Development' started by GIR, Nov 11, 2010.

  1. GIR

    GIR Well-Known Member
    18

    Feb 14, 2010
    96
    10
    18
    Classified.
    UK
    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 (Text):
    1. WebView webview = new WebView(this);
    I get this error:
    Code (Text):
    1. The constructor WebView(new View.OnClickListener(){}) is undefined
    Any help appreciated,
    GIR
     

    Advertisement

  2. id0001

    id0001 Well-Known Member
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
    Because your 'WebView webview = new WebView(this);' code is in a nested method you need to put your context in a variable since 'this' doesn't point to your activity in a nested method.
     
    GIR likes this.
  3. GIR

    GIR Well-Known Member
    18

    Feb 14, 2010
    96
    10
    18
    Classified.
    UK
    Thank you very much id0001!

    As soon as funds allow I'll be investing in Android Programming books so I'm not posting silly questions, but quite simply its people like you that take the time to answer these types of questions that help newbies to learn.

    All the best,
    GIR
     
  4. id0001

    id0001 Well-Known Member
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
    It's a java thing actually. The 'this' keyword refers to a new scope which you create by nesting.

    example:
    Code (Text):
    1.  
    2. // start of scope 1
    3. class Foo {
    4.  
    5.    int x = 0;
    6.  
    7.    public Foo {
    8.       this.x = 3 // this works because this refers to scope 1
    9.  
    10.       // start of scope 2
    11.       buttonx.setOnClickListener(new OnClickListener() {
    12.          
    13.          // this is a nested class
    14.  
    15.          public void onClick() {
    16.             this.x = 3 // this wil fail since x is not in this scope.
    17.  
    18.             // a new class scope is define by the new OnClickListener() {}
    19.             // the 'this' keyword will refer to the OnClickListener() {}
    20.          }
    21.  
    22.       });
    23.    }
    24. }
    25.  
    I hope this explains enough.
     
    GIR likes this.

Share This Page

Loading...