Fragment Android nested in nested fragments i.e. fragments Fragment

In fact, debris and nesting activities almost just change a place, tell us about the activities to be nested fragments:

Nested debris event code as follows:

void replaceFragment Private (Fragment the fragment) { 
FragmentManager FragmentManager getSupportFragmentManager = (); // here for debris manager approach differs nested debris fragments used here is getSupportFragmentManager () Note: Apparently there also may be getFragmentManager ()
FragmentTransaction Transaction = fragmentManager.beginTransaction (); // open a thing, opened by calling beginTransaction ()
transaction.replace (R.id.top_fragment, the fragment); // replace debris into the container first parameter (added using .add): the second parameter container id: fragments to be added
transaction.commit (); // commit the transaction
}

Then add in a button click event

replaceFragment(new QuotationFragment());

It can be.

NOTE: QuotationFragment () class is inherited from a fragment of Fragment simply reloading layout fragments can code as follows:

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
final View view = inflater.inflate(R.layout.fragment_account_fragment_flow,container,false);//加载布局
return view;
}

Nesting debris fragments:

To the above code simply getSupportFragmentManager second row () instead getChildFragmentManager () can, the rest of the debris and add the same activities.



 









Guess you like

Origin www.cnblogs.com/hwh000/p/11291299.html