A common footer for an entire application [Android]

折月煮酒 提交于 2019-12-02 05:27:43

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!