【问题标题】:A common footer for an entire application [Android]整个应用程序的通用页脚 [Android]
【发布时间】:2011-07-21 11:15:21
【问题描述】:

好的,我想知道这是否可以做到..

我只需要一个常见的页脚(如 bar),其中包含将要显示的广告。我想知道是否有任何方法可以将我的应用程序的这一部分作为一个通用部分。

我知道包含标签,但所做的只是在引用它的任何地方添加该特定布局。每次我从一项活动转移到另一项活动时,它都会提示重新加载广告。这很烦人,因为每次我移动到新活动时都会发送一个新的广告请求。

我正在使用 admob 来展示广告。 希望我已经把问题说清楚了。

【问题讨论】:

  • 我猜你的意思是 include 标签
  • 是的,我实际上在那里输入了“”。那没有出现在那里!
  • 您可以编辑、突出显示它并按下{} 按钮。它将添加两个倒引号(`)(这是他们的名字吗?)所以它被格式化。

标签: android footer


【解决方案1】:

以编程方式创建您的视图,然后将其存储在可在整个应用程序中访问的singleton object 中,这将避免每次都创建一个新视图。

单例类示例:

  public class MySingleFooter
{
    MySingleFooter mySingleFooter;
    View myFooter;

    private MySingleFooter()
{

}

    public static MySingleFooter getInstance()
    {
    if (mySingleFooter == null)
        {
        mySingleFooter = new MySingleFooter();
        }

    return mySingleFooter;
    }

    void setFooter(View myFooter)
    {
        this.myFooter = myFooter;
    }

    View getFooter()
    {
        return myFooter;
    }

}

您可以像这样设置所有活动的页脚:

MySingleFooter footerStore = MySingleFooter.getInstance();
footerStore.setFooter(thefooter);

您可以像这样从所有活动中检索页脚:

MySingleFooter footerStore = MySingleFooter.getInstance();
View myview = footerStore.getFooter(thefooter);

然后以编程方式将其添加到当前活动中。

【讨论】:

  • 哇。想知道为什么我以前没有想到这样的解决方案。非常感谢,完成后将对其进行测试并将您的解决方案标记为正确答案..
  • 我无法推进您的想法。请see here
猜你喜欢
  • 2013-10-16
  • 2013-07-07
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 2019-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多