android - 从自定义布局访问基本活动

时间:2013-05-15 18:10:30

标签: android layout fragment

我的片段中有一个自定义布局,它扩展了RelativeLayout

    public class Footer extends RelativeLayout

如何使用此自定义对象中的getSupportFragmentManager?当我使用this.getContext()时,它给出了Application,而不是FragmentActivity。

  The method getSupportFragmentManager() is undefined for the type Footer (extends RelativeLayout)

等待你的帮助

由于

1 个答案:

答案 0 :(得分:0)

像这样在构造函数中发送上下文

让您的活动为MyFragmentActivity

MyFragmentActivity activity;
Footer(MyFragmentActivity activity)
{
 this.context=context;
}

并从您的活动发送活动名称。这

MyFragmentActivity.this

现在你可以使用

activity.getSupportFragmentManager()