The problem of placing a fragment in another fragment

I tried putting a fragment in FrameLayout inside another fragment through FragmentManager and FragmentTransaction (from android.support.v4.app). The container fragment has a button and a TextView at the top, and a FrameLayout snapshot at the bottom (I create the layout programmatically, and I don't want to hurt you with all of this). CreateView () works just fine, and I can access the FrameLayout at the bottom of the container and add or remove the View dynamically, as I like, through

@Override public void onClick(View button) { FrameLayout frame = (FrameLayout)findViewById(DETAIL_CONTENT_FRAME); ImageView im = new ImageView(this); im.setImageResource(R.drawable.test); frame.addView(im); } 

but when I try to add a fragment instead of an ImageView in a frameLayout, the code compiles fine, but the desired fragment does not appear after the onClickListener () method is called. I checked the onCreateView () method of this fragment and returned the correct view ...

 @Override public void onClick(View button) { ServerDialogFragment serverDialog = new ServerDialogFragment(); FragmentTransaction addDialog = getSupportFragmentManager().beginTransaction(); addDialog.add(DETAIL_CONTENT_FRAME, serverDialog); addDialog.commit(); } 

Do you have an answer to this question?

PS: I once tried adding fragments to other fragments, and it worked, but they were simple fragments containing only ImageViews.

0
source share
1 answer

Fragments within other fragments are not currently supported. Cm:

+1
source

Source: https://habr.com/ru/post/910900/


All Articles