This one has me stumped.
I need to call an activity method from within a custom layout class. The problem with this is that I don't know how to access the activity from within the layout.
public class ProfileView extends LinearLayout
public ProfileView(Context context, AttributeSet attrs, String name, final ProfileData profileData)
//Heres where things get complicated
public void onClick(View v)
//Need to get the parent activity and call its method.
ProfileActivity x = (ProfileActivity) context;
public class ProfileActivityActivity extends Activity
//In here I am creating multiple ProfileViews and adding them to the activity dynamically.
public void onCreate(Bundle savedInstanceState)
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);
Activity, just pass in
this as the
Context for your layout:
ProfileView pv = new ProfileView(this, null, temp, tempPd);
Afterwards you will have a
Context in the layout, but you will know it is actually your
Activity and you can cast it so that you have what you need:
Activity activity = (Activity) context;