1.在Fragment的OnCreateView中如果要调用TextView,应该用:
TextView tv = (TextView)rootView.findViewById(R.id.tv1);
而不能用Activity中常用的:
TextView tv = (TextView)getView().findViewById(R.id.tv1);
后者编译能通过但运行会崩溃。
这说明getView()得到的view不是fragment的onCreateView中inflate出来的rootView。
参考:这里