You are right Bob, but it's a little bit more complex. You can explain this
in two words or write a paragraph. I decided half the info is better than
the complete one. You know, a simple question deserves a simple solution.
For more info, refer to the documentation :)

Anyway, the best solution would be to use the view.getContext IMO. If you
hardcode the "this" to the OuterClass then it's not really portable. Also
having globals that carry the Context is a nono that should be avoided if
possible. But alas, it's all about the damn context - no pun intended.

BR,
Adrian Vintu

http://adrianvintu.com


On Sun, Mar 28, 2010 at 3:58 AM, Bob Kerns <[email protected]> wrote:

> Actually, the first part is not true -- you just have to use the right
> 'this'. Just use MyOuterClassName.this and all will be fine.  You
> could also copy it to a final variable but there's no need since Java
> provides this mechanism for just this situation.
>
> On Mar 27, 7:44 am, Adrian Vintu <adrianvi...@gmail.
> > You need to create the TextView outside the scope of the OnClickListener.
> > The "this" has to point to Context, which is your Activity.
> >
> > BR,
> > Adrian Vintu
> >
> > http://adrianvintu.com
> >
> >
> >
> > On Sat, Mar 27, 2010 at 3:28 PM, rubeN_vl <[email protected]>
> wrote:
> > > Hi,
> >
> > > i'm trying to create a new TextView when a button is clicked.
> > > TextView b = new TextView(this); isnt working cause 'this' refers to
> > > new View.onClickListener.
> > > Been searchin for hours, cant find a solution.
> >
> > > --
> > > 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]<android-developers%[email protected]><android-developers%2Bunsubs
> [email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> > > To unsubscribe from this group, send email to android-developers+
> > > unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE
> > > ME" as the subject.
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> To unsubscribe from this group, send email to android-developers+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>

-- 
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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to