解决方案 »

  1.   

    你这是4.4的SDK吧layout是fragment的layout,所以你得在PlaceholderFragment的onviewcreate里面做findview
    或者把下面这段删掉,不去commit fragment       if (savedInstanceState == null) {
                getFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
      

  2.   

    不去commit fragment的话 你的布局文件里面的东西就要方到 setContentView(R.layout.activity_main);
    这里面加载的布局文件哦。
      

  3.   

    在mainActivity中是有函数PlaceholderFragment的,太长了,之前没贴上去:如下
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }    @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }    /**
         * 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;
            }
        }
      

  4.   

    按照两位的提示,删除了fragment_main文件,所有定义都放到了主文件中,可以通过。
    4.4的SDK会同时有两个layout出现,目前还没搞清楚两个的关系,只能先删除一个,针对另一个操作了 :)多谢
      

  5.   


    fragment理解是activity中的一个组件,4.0以后都推荐用fragment来实现,这样可以适配pad,具体的你可以去详细阅读官方文档