how to refer the context of another class

Put your problem here if it does not fit any of the other categories.

how to refer the context of another class

Postby pedroteixeira07 » Mon Jul 05, 2010 11:54 pm

Hi all,

I'm completely newbie with Android.. and I don't understand how to use the ''Context''.

I have this method:
Code: Select all
   @Override
   protected boolean onTap(int i) {
      Toast.makeText(?context?,items.get(i).getSnippet(),Toast.LENGTH_SHORT).show();
      return(true);
   }


which I took from a tutorial..

The thing is.. in the tutorial.. the class which uses this method is implemented on a main class let's call it "whatever" so the context is whatever.this

But my class that uses this, is external, so I don't know how to refer the context to the class that calls it..

Am I being clear at all ? It's so hard to explain this.. please give me some feedback or a chance to explain it on another way
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top

Re: how to refer the context of another class

Postby anarche » Tue Jul 06, 2010 2:32 am

All processes have a context that controls their permissions. All classes inside that process need to reference the Context. Most classes have a method that will get their owning Context.

Read the API further to figure out the relationship from your class to the Context
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 25 guests