使用hide / show或detach / attach从Activity刷新片段

时间:2014-03-18 13:59:41

标签: android

我正在尝试在我的数据库中完成更新后刷新活动中2个片段的内容。

我看到一些答案告诉使用隐藏/显示或附加/分离,但它对我不起作用...可能我做错了...

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

    // Create fragment and give it an argument specifying the article it should show
ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION, position);
newFragment.setArguments(args);

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();

取自此处:https://developer.android.com/training/basics/fragments/fragment-ui.html