开发者

A common footer for an entire application [Android]

OK, I wanna know if this can be done..

All I need is a common footer like bar, which will contain ads that are going to be displayed. I was wondering if there was any way by which I can have this part of my application as a common one.

I am aware of the include tag, but a开发者_如何学Goll that does is to add a that particular layout anywhere it is referenced. What that does is it prompts a reload of the ad, everytime I move from one activity to another. This is very annoying as there is a new ad request that is being sent everytime I move to a new activity.

I am using admob to display ads. Hope I have made the question clear.


Create your view programatically then store it in a singleton object which can be accessed throughout the application, this will avoid having to create a new View each time.

Singleton class example:

  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;
    }

}

You can set the footer from all activities like this:

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

You can retrieve the footer from all activities like this:

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

Then add it to the current activity programatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜