我制作了一个小的自定义视图组件:
public class ActionBar extends RelativeLayout
{
public ActionBar(Context context, AttributeSet attrs)
{
super(context, attrs);
// .. custom logic here
}
private class homeButtonListener implements OnClickListener
{
@Override
public void onClick(View v)
{
// how do i get the context here?
}
}
}
每个ActionBar组件都带有一个home按钮,所以我认为将其onClickListener放在视图定义本身中是合适的。当单击该按钮时,应该返回用户到主活动,但我需要Context以启动活动。我是否可以创建对构造函数传递的Context的本地引用,而不会遇到一堆内存泄漏问题?