Получение активности из контекста в Android

Это меня поставило в тупик.

Мне нужно вызвать метод деятельности из пользовательского класса макета. Проблема в том, что я не знаю, как получить доступ к активности из макета.

ProfileView
public class ProfileView extends LinearLayout
{
    TextView profileTitleTextView;
    ImageView profileScreenImageButton;
    boolean isEmpty;
    ProfileData data;
    String name;

    public ProfileView(Context context, AttributeSet attrs, String name, final ProfileData profileData)
    {
        super(context, attrs);
        ......
        ......
    }

    //Heres where things get complicated
    public void onClick(View v)
    {
        //Need to get the parent activity and call its method.
        ProfileActivity x = (ProfileActivity) context;
        x.activityMethod();
    }
}
ProfileActivity
public class ProfileActivityActivity extends Activity
{
    //In here I am creating multiple ProfileViews and adding them to the activity dynamically.

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_activity_main);
    }

    public void addProfilesToThisView()
    {
        ProfileData tempPd = new tempPd(.....)
        Context actvitiyContext = this.getApplicationContext();
        //Profile view needs context, null, name and a profileData
        ProfileView pv = new ProfileView(actvitiyContext, null, temp, tempPd);
        profileLayout.addView(pv);
    }
}

Как вы можете видеть выше, я создаю экземпляр profileView программно и передаю им код ActivityContext. 2 вопроса:

Я передаю правильный контекст в профиль?Как я могу получить содержащую деятельность из контекста?

Ответы на вопрос(9)

Ваш ответ на вопрос