import java.util.Date;
import java.util.LinkedList; import com.qianfeng.gp08_day23_fragment5.fragment.TestFragment; import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.view.Menu;
import android.view.View; /**
*
*
*
*/
public class MainActivity_2 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void addFragment(View v) {
TestFragment fragment = new TestFragment();
Bundle bundle = new Bundle();
bundle.putString("msg", "xixi" + new Date());
fragment.setArguments(bundle); FragmentTransaction tran = getFragmentManager().beginTransaction(); tran.add(R.id.container, fragment);//remove1 add 2 tran.addToBackStack(null);//把事务加入当前的回退栈 回滚 tran.commit();
} // 点击回退按钮显示上一个fragment
public void backFragment(View v) { onBackPressed();
}
}

MainActivity

 import android.app.Activity;
import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; public class TestFragment extends Fragment { private String args; @Override
public void onAttach(Activity activity) {
args = getArguments().getString("msg");
super.onAttach(activity);
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
textView.setText(args);
int red = (int)(Math.random()*256);
int green = (int)(Math.random()*256);
int blue = (int)(Math.random()*256); textView.setBackgroundColor(Color.rgb(red, green, blue));
return textView;
} }

TestFragment

此方法是动态创建fragment

fragment 事务回滚 ---动态创建fragment的更多相关文章

  1. Android 动态创建Fragment

    Fragment是activity的界面中的一部分或一种行为.可以把多个Fragment组合到一个activity中来创建一个多界面并且可以在多个activity中重用一个Fragment.可以把Fr ...

  2. Fragment 事务 回退栈

    一些相关API 1.Fragment常用的三个类: android.app.Fragment 定义android.app.FragmentManager 用于在Activity中操作Fragmenta ...

  3. Spring中@Transactional事务回滚

    转载: Spring中@Transactional事务回滚 一.使用场景举例 在了解@Transactional怎么用之前我们必须要先知道@Transactional有什么用.下面举个栗子:比如一个部 ...

  4. 事务之二:spring事务(事务管理方式,事务5隔离级别,7个事务传播行为,spring事务回滚条件)

    事物管理对于企业应用来说是至关重要的,好使出现异常情况,它也可以保证数据的一致性. spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务管理使用TransactionTemplate或 ...

  5. Spring 事务回滚机制详解

    1:事务原理 1.2:aop/动态代理 类路径:org/springframework/aop/framework/CglibAopProxy.java ReflectiveMethodInvocat ...

  6. SQL 事务回滚

    事务(Transaction)是并发控制的单位,是用户定义的一个操作序列.这些操作要么都做,要么都不做,是一个不可分割的工作单位.通过事务,SQL Server能将逻辑相关的一组操作绑定在一起,以便服 ...

  7. 【Java EE 学习 19】【使用过滤器实现全站压缩】【使用ThreadLocal模式解决跨DAO事务回滚问题】

    一.使用过滤器实现全站压缩 1.目标:对网站的所有JSP页面进行页面压缩,减少用户流量的使用.但是对图片和视频不进行压缩,因为图片和视频的压缩率很小,而且处理所需要的服务器资源很大. 2.实现原理: ...

  8. SqlServer事务回滚(2)

    SQL Server 2008中SQL应用系列--目录索引 SQL事务 一.事务概念    事务是一种机制.是一种操作序列,它包含了一组数据库操作命令,这组命令要么全部执行,要么全部不执行.因此事务是 ...

  9. Spring @Transactional ——事务回滚

    工作原理运行配置@Transactional注解的测试类的时候,具体会发生如下步骤1)事务开始时,通过AOP机制,生成一个代理connection对象,并将其放入DataSource实例的某个与Dat ...

随机推荐

  1. js将UTC时间转化为当地时区时间

    js将UTC时间转化为当地时区时间(UTC转GMT)   我们在进行网站开发的时候有可能会涉及到国外的用户或者用户身在国外,这时就会存在时差问题,比如说我们在中国的时间是08:00,但是此时韩国的时间 ...

  2. 对话框(VC_Win32)

    资源描述表中对话框定义 格式: 对话框名 DIALOG[载入特性] X,Y,Width,Height[设置选项] { 对话框控件定义; } 说明: 对话框名称: 标识对话框资源,可为一个字符串也可以为 ...

  3. JS获取url传参

    function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new O ...

  4. php笔记篇(二)

    mysql中key .primary key .unique key 与index区别(http://www.manongjc.com/article/1487.html) php is_file() ...

  5. python logging模块使用教程

    简单使用 #!/usr/local/bin/python # -*- coding:utf-8 -*- import logging logging.debug('debug message') lo ...

  6. elastisSearch-aggregations

    运行结果 统计每个学员的总成绩 这个是索引库使用通配符 优先在本地查询 只在本地节点中查询 只在指定id的节点里面进行查询 查询指定分片的数据 参考代码ESTestAggregation.java p ...

  7. Linux火焰图-centos

    centos7.5mini安装 yum install -y yum-utils perf debuginfo-install -y perf #debuginfo-install下载了305MB的文 ...

  8. 并发基础(九) java线程的终止与中断

    1.简单了解一下:为何不赞成使用 Thread.stop.Thread.suspend 和 Thread.resume?   suspend .resume.stop方法分别完成了线程的暂停.恢复.终 ...

  9. (16/24) webpack打包后的调试方法

    在程序开发中,调试程序是最频繁的,那使用了webpack后,所有的代码都打包到了一起,这给调试带来了困难,但是webpack在设计时就已经考虑好了这点,它支持生产Source Maps来方便我们的调试 ...

  10. zabbix 监控数据库 及 tcp连接数

    参考网站: 监控sqlserver      http://blog.51cto.com/13272050/2050601 http://blog.51cto.com/ultrasql/1927672 ...