2

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

    public class Footer extends RelativeLayout

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

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

等待您的帮助

谢谢

4

1 回答 1

0

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

让您的活动成为MyFragmentActivity

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

并从您的 Activity 发送 Activity name.this

IE

MyFragmentActivity.this

现在你可以使用

activity.getSupportFragmentManager()
于 2013-05-15T18:15:03.850 回答