我希望在startActivityForResult的帮助下将数据从我的适配器类传递到另一个片段。如果我使用下面的代码相同的活动重新创建它我不想要那样。如何解决这个问题?
Bundle mBundle = new Bundle();
mBundle.putString(Constants.SELECTED_PLOCATION, pLocation);
mBundle.putString(Constants.SELECTED_RLOCATION, rLocation);
mBundle.putString(Constants.SELECTED_FROM, selectedFrom);
mBundle.putString(Constants.FROM_TYPE, fromType);
mBundle.putString(Constants.AREA_TYPE, Constants.AREA);
getActivity().getFragmentManager().popBackStackImmediate();
Intent mIntent = new Intent(getActivity(), AuthorizedCustomerActivity.class);
getActivity().startActivityForResult(mIntent, PICK_LOCATION_REQUEST, mBundle);
答案 0 :(得分:0)
使用以下代码从适配器到片段的数据传输;
Fragment fragment = new YourFragmentName();
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
Bundle mBundle= new Bundle();
mBundle.putString(Constants.SELECTED_PLOCATION, pLocation);
mBundle.putString(Constants.SELECTED_RLOCATION, rLocation);
mBundle.putString(Constants.SELECTED_FROM, selectedFrom);
mBundle.putString(Constants.FROM_TYPE, fromType);
mBundle.putString(Constants.AREA_TYPE, Constants.AREA);
fragment.setArguments(mBundle);