。 我有一個片段文件片斷,並在它的一些onclicks在那裏。我想開上click事件的新片段,但它是開放以前的片段,地方堆棧中丟失或別的東西,我無法找到答案。錯誤的片段加載時,我想當我試圖加載它加載之前的片段的新片段加載新的
relativeLayoutManagement.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction;
if(getParentFragment() == null){
transaction = childFragmentManager.beginTransaction();
}else {
transaction = childFragmentManagerOfParent.beginTransaction();
transaction.replace(R.id.frameLayoutChildContainer, HotelManagementFragment.newInstance(),FragmentTags.HOTEL_MANAGEMENT);
transaction.addToBackStack(FragmentTags.HOTEL_MANAGEMENT);
transaction.commit();
}
}
});
}
這是我的新片段代碼。
public class HotelManagementFragment extends BaseFragment {
public HotelManagementFragment() {
}
public static HotelManagementFragment newInstance() {
HotelManagementFragment fragment = new HotelManagementFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_hotel_managment, container, false);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
}
後只需要** **代碼不是全班 – mklimek