Problem when moving from one Fragmen to another Fragment

0

I have some Fragment classes in which I have added some buttons to go from one Fragmen to another Fragmen.

I have commented that for the transitions between Fragment we use FragmentTransaction and instead of getFragmentManager or getSupportFragmentManager that is used getChildFragmentManager

I do not know if I'm doing it right, but it's not working for me, this is the code that does not work for me:

botonSF.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SegundoF fragment = new SegundoF();
            FragmentTransaction ftSF = getChildFragmentManager().beginTransaction();
            ftSF.replace(R.id.frame_container, fragment);
            ftSF.addToBackStack(null);
            ftSF.commit();

        }
    });

On the other hand, using this other code if I can move from one Fragment to another Fragment, I do not know if in the future it could give any problem by not using FragmentTransaction

botonSF.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
                getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .replace(android.R.id.content, new SegundoF())
                        .addToBackStack(null)
                        .commit();
        }
    });

I really do not know why it works, because if you look, in the first code to replace the fragment I use R.id.frame_container instead it's the second code I use android.R. id.content ;

in activity_main.xml

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </FrameLayout>

How does this second code work if in the activity_main.xml I have "@ + id / frame_container"? And why does not the first code work?

Then when I show the content of the second Fragment, it stays on top of the menu, it is superimposed on the TabLayout Because the Fragment is shown above the menu, how could I put it below so that it does not cover the menu?

This example video shows what I have said and the problem with the Fragment link

Another problem that I encountered on another occasion is that the fragment is shown one on top of the other, as you can see in this example video.
link

This case is not superimposed on the menu, but the two fragments are shown, as I can avoid that the two fragments are not shown.

Logcat of the video showing the error

2018-12-08 19:00:31.037 19096-9071/? E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2018-12-08 19:00:32.800 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:00:41.076 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:00:47.663 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:01:08.036 12055-12055/? E//system/bin/webview_zygote32: Failed to make and chown /acct/uid_99075: Permission denied
2018-12-08 19:01:08.036 12055-12055/? E/Zygote: createProcessGroup(99075, 0) failed: Permission denied
2018-12-08 19:01:08.078 12077-12077/? E/asset: setgid: Operation not permitted
2018-12-08 19:01:23.399 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:01:57.239 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:02:57.309 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:03:33.258 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:03:33.258 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:03:33.950 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:03:33.951 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:03:34.564 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:03:34.565 11988-12007/com.darwindeveloper.horizontalscrollmenu E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2018-12-08 19:04:00.027 18710-18723/? E/memtrack: Couldn't load memtrack module
2018-12-08 19:04:21.144 19096-9071/? E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2018-12-08 19:04:23.304 11988-11988/com.darwindeveloper.horizontalscrollmenu E/FragmentManager: No view found for id 0x7f070048     (com.darwindeveloper.horizontalscrollmenu:id/frame_container) for fragment Esta_S_Ga{28445a #0 id=0x7f070048}
2018-12-08 19:04:23.304 11988-11988/com.darwindeveloper.horizontalscrollmenu E/FragmentManager: Activity state:
2018-12-08 19:04:23.343 11988-11988/com.darwindeveloper.horizontalscrollmenu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.darwindeveloper.horizontalscrollmenu, PID: 11988
java.lang.IllegalArgumentException: No view found for id 0x7f070048 (com.darwindeveloper.horizontalscrollmenu:id/frame_container) for fragment     Esta_S_Ga{28445a #0 id=0x7f070048}
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1413)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
    at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
2018-12-08 19:04:24.574 19096-11457/? E/ctxmgr: [ProducerStatusImpl]updateStateForNewContextData: inactive, contextName=7
2018-12-08 19:04:24.844 19096-19096/? E/BeaconBle: Missing BluetoothAdapter
2018-12-08 19:04:24.878 19096-19096/? E/BeaconBle: Scan couldn't start for Places

Thanks.

    
asked by SoCu 05.12.2018 в 15:34
source

1 answer

0

In the code where you use android.R.id.content , if you work with FragmentTransaction using the beginTransaction () method.

Replaces

getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .replace(android.R.id.content, new SegundoF())
                        .addToBackStack(null)
                        .commit();

By

getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.frame_container, new SegundoF())
                        .addToBackStack(null)
                        .commit();
    
answered by 05.12.2018 в 18:00