多个fragment切换,而不重新加载数据的实现
1、在xml中添加一个framlayout
2、初始化所有fragment,并添加一个fragment显示
private void initFragment() {
allfragment = new Ts_All_Fr服务器托管网agment();
unstartfragment = new Ts_unstart_Fragment();
finishfragment = new Ts_finish_Fragment();
startfragment = new Ts_start_Fragment();
mFragmentMan = getSupportFragmentManager();
FragmentTransaction ft = mFragmentMan.beginT服务器托管网ransaction();
ft.add(R.id.framelayout,startfragment).commit();
mContent = startfragment;
}
3、当点击控件时,切换fragment 调用下面的方法
public void switchContent(Fragment to) {
if (mContent != to) {
FragmentTransaction transaction = mFragmentManager.beginTransaction().setCustomAnimations(
android.R.anim.fade_in, android.R.anim.fade_out);
// 先判断是否被add过
if (!to.isAdded()) {
// 隐藏当前的fragment
transaction.hide(mContent).add(R.id.framelayout, to).commit();
}else {
transaction.hide(mContent).show(to).commit(); //提交
}
mContent = to;
}
}
4、在监听方法中调用即可:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ts_activity_tv1:
switchContent( allfragment);
break;
case R.id.ts_activity_tv2:
switchContent( unstartfragment);
break;
case R.id.ts_activity_tv3:
switchContent( startfragment);
break;
case R.id.ts_activity_tv4:
switchContent(finishfragment);
break;
default:
break;
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
一个MySQL死锁问题的解决最近在项目开发过程中,碰到了数据库的死锁问题,在解决问题的过程中,加深了对MySQL InnoDB引擎锁机制的理解。我们使用Show innodb status检查引擎状态时,发现了死锁问题:*** (1) TRANSACTION:…