FragmentOne
我在这里取代FragmentTwo
Fragment secondFragment = new FragmentTwo();
secondFragment.setTargetFragment(FragmentOne.this, AppConstant.FRAGMENT_CODE);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_switch, secondFragment);
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
From Fragment Two如何将此“地址”字符串发送到FragmentOne中的OnActivityResult方法。我是否需要使用setArgument或getTargetFragment。
FragmentTwo
“我如何识别FragmentOne然后我可以将结果发送到FragmentOne”
FragmentOne
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
String value = data.getStringExtra("Address");
}
请帮帮我
答案 0 :(得分:3)
使用结果创建一个intent,然后在FragmentTwo中调用getTargetFragment().onActivityResult(AppConstant.FRAGMENT_CODE,Context.RESULT_OK, intent);