标签:err android .com create 生命周期 com name res turn
思路:
第一步。建立一个activity。用来管理fragment。
第二步‘获取fragmentManger 和fragmentTraction.
private FragmentManager fm; private FragmentTransaction ft; fm = getFragmentManager(); ft = fm.beginTransaction();
第三步,调用切换方法
ft.replace(android.R.id.content, new Fragment01()); ft.commit();
第四步,建立fragment
4.1 复写方法fragment生命周期方法
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment01, null); } @SuppressLint("NewApi") @Override public void onViewCreated(View view, Bundle savedInstanceState) { // TODO Auto-generated method stub super.onViewCreated(view, savedInstanceState); initView(view); } private void initView(View view) { btn=(Button) view.findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { <strong>getFragmentManager().beginTransaction().replace(android.R.id.content, new Fragment02()).commit();</strong> } }); }
标签:err android .com create 生命周期 com name res turn
原文地址:http://www.cnblogs.com/mfmdaoyou/p/6915838.html