动态fragment

版本适配 v4.fragment fragmentActivity supportFragmentManager

  fragment = new myfragment();
        android.support.v4.app.FragmentManager supportFragmentManager = getSupportFragmentManager();

        android.support.v4.app.FragmentTransaction beginTransaction = supportFragmentManager.beginTransaction();
        beginTransaction.add(R.id.de, fragment);
        beginTransaction.commit();

// 注意如果不是作为root返回第三个参数记得写false否则会报错 youshould removeView();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.dd, container,false);
        System.out.println("haha");
        
        return inflate;
    }

你可能感兴趣的:(动态fragment)