将活动拆分为多个文件

时间:2013-07-28 10:06:16

标签: android android-activity android-fragments

我正在编写一个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 {}
}

提前谢谢!

1 个答案:

答案 0 :(得分:2)

  

现在我想知道有没有办法将该活动拆分成几个文件 - 为每个片段分别创建文件

如果上述意味着您最近将所有片段作为Activity类中的内部类,则回答为yes - 只需为每个片段创建单独的java类文件。

相关问题