> I have a custom view that needs a reference to the activity that
> created it.
>
> Dianne Hackborn said in another thread:
>>Give your view a reference to the activity (or a Java interface it
>> implements) and call back through that.
>>Much much MUCH more efficient than sending a broadcast.
>>See all of the standard view and view subclass callbacks for examples.
>
> Sadly, I dont understand her reply and cant find any decent examples
> that show how to do this.
>
> Can anyone point me to an example or post one here?

Your activity is probably already available in your View via getContext().

If not, adjust your custom View's constructor to take an Activity as the
first parameter, and hold onto that Activity in your View:

public class MyCustomView extends View {
  private Activity momma;

  MyCustomView(Activity momma) { // and possibly other parameters
    super(momma); // View requires a Context; Activity is a Context
    this.momma=momma;
    // other stuff here
  }
}

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html



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

Reply via email to