它是可能的可变传递到从另一个片段一个previous片段? [英] It is Possible to Pass a variable to a Previous Fragment from another Fragment?
问题描述
我试着去传递一个变量回到previous片段,类似startActivityForResult但碎片,这可能吗?
Im trying to pass a variable back to a previous Fragment, similar to startActivityForResult but with Fragments, Is this possible?
在code我使用要调用片段是这样的:
The code I am using To call a Fragment is this:
FragmentFullScreen fragment = new FragmentFullScreen();
Bundle args = new Bundle();
args.putParcelable(ARG_VIDEO_SELECTED, mVideoSelected);
fragment.setArguments(args);
getFragmentManager().beginTransaction()
.replace(R.id.container, FragmentFullScreen.newInstance(mVideoSelected))
.addToBackStack("FragmentDetails")
.commit();
然后我用popBackStack要到previous片段:
And then I using popBackStack to go to the previous Fragment:
getFragmentManager().popBackStack();
还有就是当我想更新从previous片段的变量。
And there is when I want to update a Variable from the Previous Fragment.
推荐答案
片段之间的通信应通过活动来完成。并实现片段和活动之间的沟通,这是最好的办法<一href=\"http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity\" rel=\"nofollow\">http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity.
Communication between fragments should be done via the activity. And to achieve this communication between fragment and activity, this is the best way http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity.
这篇关于它是可能的可变传递到从另一个片段一个previous片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!