您的位置:首页 > 其它

fragment(2、动态创建)

2013-03-22 09:25 169 查看
frament可以由自动添加,主要代码如下:

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
mDemo = new DemoFragment();
transaction.replace(R.id.fragment_content, mDemo);
transaction.commit();


同时可以对每次fragment的操作增加回退栈,增加后back键的操作将首先处理fragment的回退,如下:

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
mDemo = new DemoFragment();
transaction.replace(R.id.fragment_content, mDemo);//replace = remove + add
transaction.addToBackStack(null);
transaction.commit();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: