Android创建可重用的布局

时间:2013-01-11 04:29:32

标签: android static singleton

如何使用可在应用上的任何位置调用的文本框创建单个弹出式布局。请参阅下面我的意思的伪代码;

PopUpClass popup;
private static Singleton instance = null;
class Singleton {
   if(instance == null) {
      instance = new Singleton ();
      // Instantiate a class pop up class layout
       popup = new PopUpClass(); // I dont know how to create this one
    }
    return instance;
}


SomeClass {
   private buttonClicked {
   Singleton singleton = new Singleton();
   PopUpClass popup = singleton.popup;

   //add the pop up class to current view
   }
}

这意味着我只想创建一次弹出类,以便在某些类上完成的布局上的任何文本也可以在其他类上显示。

1 个答案:

答案 0 :(得分:2)

如果要在每个布局中显示相同的文本框或其他窗口小部件,那么更好的方法是创建布局并在要显示此活动的每个活动中包含此布局。 可以参考此链接link