本帖最后由 love1017best 于 2014-07-06 17:30:49 编辑

解决方案 »

  1.   

    这个方法不可能不能用, 重启 eclipse , 重启电脑 选择 菜单 Project --> clean看看其它的代码是否可以自动提示. 可能是你的 eclipse自动提示 需要设定 
      

  2.   

    我也是新手,不过我觉得你应该将执行的代码,写到:public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    的下面。然后找id的时候,用 UserNameEditText = (EditText) rootView.findViewById(R.id.name);   这种的方式。
      

  3.   

    可以,一般都是在Fragment的onCreateView加载布局,所以可以再这里findViewById,不过常用的到是在onActivityCreated里面获取getView().findViewById(),以及处理一些点击事件
      

  4.   

    你把组件写在那个xml 里了 是activity_main吗?
      

  5.   

    commit方法应该是通过handler来post执行的,所以立刻在下面findViewByid会找不到
      

  6.   


    同意2楼的。组件都放到Fragment里了,而Activity的onCreate方法还没有填充Fragment的布局,所以拿不到组件的引用。
    在Fragment的onCreateView方法中,用rootView.findViewById方法可以获取组件的引用
      

  7.   

    2L正解,或者不用Fragment。
    将 setContentView(R.layout.activity_main);
             
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment()).commit();
            }   替换为
     setContentView(R.layout.fragment_main);