[tssg-tech] Re: Android "context" question

  • From: Jim Cant <cant_jim@xxxxxxxxxxx>
  • To: tssg tech <tssg-tech@xxxxxxxxxxxxx>
  • Date: Sun, 14 Nov 2010 10:34:36 -0500

This might be an inner class issue rather than a Context issue.

Off the top of my head, it seems as if there might be to 'this'es in the scope 
of the instance of the inner class.  One this would be for the instance of the 
inner class itself and the other  this would be for the instance of the outer 
containing class.

You might try logging the values for these possibilities to see how they behave 
and are related.  The hashCode() method will give you a value for an object 
that's sorta, kinda, like the 'this pointer' in the C++ world.

Cheers,

jim

From: pn@xxxxxxxxx
To: tssg-tech@xxxxxxxxxxxxx
Subject: [tssg-tech] Android "context" question
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: