How to prevent Eclipse from creating fragment_main.xml

后端 未结 2 1583
旧巷少年郎
旧巷少年郎 2021-02-10 22:56

I installed Eclipse on a new machine and it keeps creating fragment_main.xml when I create a new Android Application Project. How can I prevent Eclipse from doing t

2条回答
  •  醉酒成梦
    2021-02-10 23:35

    1.Creat project normally.

    2.Copy fragment_main.xml to activity_main.xml (content). Then delete fragment_main.xml

    3.In MainActivity.java delete the following content :

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
    

    and

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
    
        public PlaceholderFragment() {
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }
    

    enjoy it.

提交回复
热议问题