2013-07-28 129 views
0

我正在编写一个android应用程序,它有一个活动,其中包含多个片段。现在我想知道有没有办法将该活动分成几个文件 - 每个片段都有单独的文件?将活动拆分为多个文件

为了使我的问题更清楚,这里是我的活动结构

public class MainActivity extends Activity implements ActionBar.TabListener 
{ 
     @Override 
     public Fragment getItem(int position) { 
      switch(position) 
      { 
       case 0: 
        return new Fragment1(); 
       case 1: 
        return new Fragment2(); 
       case 2: 
        return new Fragment3(); 
       case 3: 
        return new Fragment4(); 
      } 
     } 

    public static class Fragment1 extends Fragment {} 

    public static class Fragment2 extends Fragment {} 

    public static class Fragment3 extends Fragment {} 

    public static class Fragment4 extends Fragment {} 
} 

预先感谢您!

回答

2

现在我想知道有没有办法到活动分成几个文件 - 有单独的文件每个片段

如果您最近买了你所有的片段作为内部类以上手段在您的Activity类中,然后回答是yes - 只为每个片段创建单独的java类文件。