Fragment并不是由FragmentManage去管理的,它跟数据库一样,都由一个触发器去管理,触发器管理有一个特征,它需要commit,你只有提交了,你的事件才会去执行。
来看看sqlite怎么去执行查询语句
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')
# Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
# Save (commit) the changes
conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
再来看看fragment怎么被执行
//初始化默认fragment的加载
private void initDefaultFragment() {
//开启一个事务
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
//add:往碎片集合中添加一个碎片;
//replace:移除之前所有的碎片,替换新的碎片(remove和add的集合体)(很少用,不推荐,因为是重新加载,所以消耗流量)
//参数:1.公共父容器的的id 2.fragment的碎片
fragmentTransaction.add(R.id.framelayout, mFragmentOne);
fragmentTransaction.addToBackStack(null);
//提交事务
fragmentTransaction.commit();
fragmentNow = mFragmentOne;
}
网友评论