[tssg-tech] Android "context" question

  • From: "Peter Nelson" <pn@xxxxxxxxx>
  • To: <tssg-tech@xxxxxxxxxxxxx>
  • Date: Sun, 14 Nov 2010 10:14:07 -0500

 

 

Can someone point me to a good tutorial on Android context?    As a noob,
there's obviously something I'm not getting about it.  

Recently I wrote a program were I defined a Listener class within my
Activity class (named Pdj)  - so I had a class within a class.  In the inner
class I tried to create an ArrayAdapter thusly:

 

ArrayAdapter<String> aa = new ArrayAdapter<String>(this,


 
android.R.layout.simple_list_item_1,


                                          todoArrayList);

 

But I got a build eror "The constructor ArrayAdapter(Pdj.ButtonListener,
int, ArrayList) is undefined"

The solution was to qualify my "this" thusly:

 

ArrayAdapter<String> aa = new ArrayAdapter<String>(Pdj.this,


 
android.R.layout.simple_list_item_1,


                                          todoArrayList);

 

Why is it necessary to qualify the context here?   The inner class object is
invoked from the outer class  and the inner class can see and use member
variables of the outer class.   Not only that but the error message The
constructor ArrayAdapter(Pdj.ButtonListener, int, ArrayList) is undefined
implies that the compiler recognizes that the current class is part of Pdj!
So obviously there's something about context I'm not getting.

 

Thanks in advance.

 

 

Peter Nelson

 

Other related posts: