use of android.support.v4.app.FragmentTransaction in project DesignLibrary by StylingAndroid.
the class ArticleViewPagerAdapter method destroyItem.
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
super.destroyItem(container, position, object);
}
use of android.support.v4.app.FragmentTransaction in project GT by Tencent.
the class GTMainActivity method setTabSelection.
/**
* 根据传入的index参数来设置选中的tab页。
*
* @param index
* 每个tab页对应的下标。
*/
private synchronized void setTabSelection(int index) {
// 每次选中之前先清楚掉上次的选中状态
clearSelection();
// 开启一个Fragment事务
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
// 先隐藏掉所有的Fragment,以防止有多个Fragment显示在界面上的情况
//TODO
hideFragments(transaction);
switch(index) {
case 0:
// 当点击了AUT tab时,改变控件的图片和文字颜色
autImage.setImageResource(R.drawable.tab_selected_border);
autText.setTextColor(Color.WHITE);
if (autFragment == null) {
autFragment = new GTAUTFragment();
transaction.add(R.id.content, autFragment, "a");
} else {
transaction.show(autFragment);
}
break;
case 1:
// 当点击了参数 tab时,改变控件的图片和文字颜色
paramImage.setImageResource(R.drawable.tab_selected_border);
paramText.setTextColor(Color.WHITE);
if (paramFragment == null) {
paramFragment = new GTParamTopFragment();
transaction.add(R.id.content, paramFragment, "b");
} else {
transaction.show(paramFragment);
paramFragment.onShow(true);
}
break;
case 2:
// 当点击了耗时 tab时,改变控件的图片和文字颜色
perfImage.setImageResource(R.drawable.tab_selected_border);
perfText.setTextColor(Color.WHITE);
if (perfFragment == null) {
perfFragment = new GTPerfFragment();
transaction.add(R.id.content, perfFragment, "c");
} else {
transaction.show(perfFragment);
}
break;
case 3:
// 当点击了日志 tab时,改变控件的图片和文字颜色
logImage.setImageResource(R.drawable.tab_selected_border);
logText.setTextColor(Color.WHITE);
if (logFragment == null) {
logFragment = new GTLogFragment();
transaction.add(R.id.content, logFragment, "d");
} else {
transaction.show(logFragment);
}
break;
case 4:
default:
// 当点击了插件 tab时,改变控件的图片和文字颜色
pluginImage.setImageResource(R.drawable.tab_selected_border);
pluginText.setTextColor(Color.WHITE);
if (pluginFragment == null) {
pluginFragment = new GTPluginFragment();
transaction.add(R.id.content, pluginFragment, "e");
} else {
transaction.show(pluginFragment);
}
break;
}
/*
* 直接使用commit()可能会出错:
* IllegalStateException: Can not perform this action after onSaveInstanceState:\
*
* @see http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()
*
* 大致意思是说我使用的 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState
* 方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就
* 是把commit()方法替换成 commitAllowingStateLoss()就行了,其效果是一样的。
*/
// transaction.commit();
transaction.commitAllowingStateLoss();
}
use of android.support.v4.app.FragmentTransaction in project GT by Tencent.
the class GTMainActivity method removeFragments.
/*
* 在Activity重新加载时,要先清除遗留的Fragment
*/
private void removeFragments() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment fragment = fragmentManager.findFragmentByTag("a");
if (fragment != null) {
transaction.remove(fragment);
}
fragment = fragmentManager.findFragmentByTag("b");
if (fragment != null) {
transaction.remove(fragment);
}
fragment = fragmentManager.findFragmentByTag("c");
if (fragment != null) {
transaction.remove(fragment);
}
fragment = fragmentManager.findFragmentByTag("d");
if (fragment != null) {
transaction.remove(fragment);
}
fragment = fragmentManager.findFragmentByTag("e");
if (fragment != null) {
transaction.remove(fragment);
}
transaction.commitAllowingStateLoss();
}
use of android.support.v4.app.FragmentTransaction in project GT by Tencent.
the class GTParamTopFragment method setFragSelection.
/**
* 根据传入的index参数来设置选中的Fragment页。
*
* @param index
* 每个Fragment页对应的下标。
*/
private void setFragSelection(int index) {
// 每次选中之前先清楚掉上次的选中状态
clearSelection();
// 开启一个Fragment事务
FragmentTransaction transaction = fragmentManager.beginTransaction();
// 先隐藏掉所有的Fragment,以防止有多个Fragment显示在界面上的情况
hideFragments(transaction);
switch(index) {
case 0:
// 入参
btnIn.setBackgroundResource(R.drawable.swbtn_selected);
btnIn.setTextColor(Color.WHITE);
if (inFragment == null) {
inFragment = new GTParamInFragment();
transaction.add(R.id.content, inFragment);
} else {
transaction.show(inFragment);
}
break;
case 1:
// 出参
btnOut.setBackgroundResource(R.drawable.swbtn_selected);
btnOut.setTextColor(Color.WHITE);
if (outFragment == null) {
outFragment = new GTParamOutFragment();
transaction.add(R.id.content, outFragment);
} else {
transaction.show(outFragment);
}
break;
case 2:
// 入参编辑
btnIn.setBackgroundResource(R.drawable.swbtn_selected);
btnIn.setTextColor(Color.WHITE);
if (inEditFragment == null) {
inEditFragment = new GTParamInEditFragment();
transaction.add(R.id.content, inEditFragment);
} else {
transaction.show(inEditFragment);
}
break;
case 3:
// 出参编辑
btnOut.setBackgroundResource(R.drawable.swbtn_selected);
btnOut.setTextColor(Color.WHITE);
if (outEditFragment == null) {
outEditFragment = new GTParamOutEditFragment();
transaction.add(R.id.content, outEditFragment);
} else {
transaction.show(outEditFragment);
}
break;
default:
break;
}
/*
* 直接使用commit()可能会出错:
* IllegalStateException: Can not perform this action after onSaveInstanceState:\
*
* @see http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()
*
* 大致意思是说我使用的 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState
* 方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就
* 是把commit()方法替换成 commitAllowingStateLoss()就行了,其效果是一样的。
*/
// transaction.commit();
transaction.commitAllowingStateLoss();
}
use of android.support.v4.app.FragmentTransaction in project SeriesGuide by UweTrottmann.
the class ExtensionsConfigurationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_singlepane);
setupActionBar();
if (getIntent().hasExtra(SeriesGuideExtension.EXTRA_FROM_SERIESGUIDE_SETTINGS)) {
// launch Amazon extension settings instead
if (savedInstanceState == null) {
AmazonConfigurationFragment f = new AmazonConfigurationFragment();
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.content_frame, f);
ft.commit();
}
} else {
if (savedInstanceState == null) {
ExtensionsConfigurationFragment f = new ExtensionsConfigurationFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.content_frame, f);
ft.commit();
}
}
}
Aggregations