【问题标题】:android - access base activity from custom layoutandroid - 从自定义布局访问基本活动
【发布时间】:2013-05-10 10:38:32
【问题描述】:

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

    public class Footer extends RelativeLayout

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

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

等待您的帮助

谢谢

【问题讨论】:

    标签: android layout fragment


    【解决方案1】:

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

    让你的活动是MyFragmentActivity

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

    然后从您的 Activity 发送 Activity name.this

    MyFragmentActivity.this
    

    现在你可以使用

    activity.getSupportFragmentManager()
    

    【讨论】:

    • 效果很好 :) 非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多