I had this exact question a while ago, when I was building some custom
View components. What I wanted was a little more complicated though -
it was basically this.

Basic containing view, set in the Activity class itself
Several classes stored inside the activity with views defined *inside
those classes*
I needed these external views to be able to launch subactivities and
deal with the return codes themselves.

At first this seemed kind of nasty, because the functionality I wanted
for my non-activity view classes is *only* available in an activity!
The solution, as it turns out, was pretty simple - define your own
constructor for those classes, and pass in the activity. Then you can
just call whatever you need to on it. It works like this:

public class MyActivity extends View{

  private final Activity mActivity;

  public MyActivity(Activity a){
    super(a); //since Activity extends context, this works just fine
    mActivity = a;
    ...
  }

  @Override
  public void onClick(View v){
   ...
   mActivity.startSubActivity(...);
   ...
  }

}

Dealing with the return codes was a little trickier, but it doesn't
sound like that's what you need right now. If it is, just ask. :)

 - TM
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to