Two solutions:

Remove the 'this':
               okIntent.putExtra("com.example.challenge_no",
               challenge_number);    // This is the problem line
               startActivity(okIntent);
               finish();

Or add Example.:
               okIntent.putExtra("com.example.challenge_no",
               Example.this.challenge_number);    // This is the
problem line
               startActivity(okIntent);
               finish();


On Oct 12, 12:56 am, Tom <[email protected]> wrote:
> There is a probably a very simple answer to this, but I would like to
> do the following:
>
> public class Example extends Activity {
>
>     private String challenge_number = "";
>
>    .....class code....
>
>     Button ok_button = new Button(this);
>     ok_button.setOnClickListener(new View.OnClickListener()
>     {
>            public void onClick(View args0)
>            {
>                Intent okIntent = new Intent();
>                okIntent.setClassName("com.example",
> "com.example.newPage");
>
>                okIntent.putExtra("com.example.challenge_no",
> this.challenge_number);    // This is the problem line
>                startActivity(okIntent);
>                finish();
>            }
>
> }
>
> It fails because the listener doesn't know what "this.challenge_no"
> is.  Can anyone help me solve this problem of scope?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to