AlertDialog with FragmentManager

0
public void mapaDialog(View view){

    AlertDialog.Builder mBuilder = new AlertDialog.Builder(CadastroAbrigo.this);
    View mView = getLayoutInflater().inflate(R.layout.mapa_flutuante, null);

    FragmentManager fragmentManager;

    fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(R.id.fragmentFlutuante, new MapsFragment(), "MapsFragment");
    transaction.commitAllowingStateLoss();

    mBuilder.setView(mView);
    final AlertDialog dialog = mBuilder.create();
    dialog.show();

}

Good afternoon guys, I'm trying to inflate a layout with FragmentManager, I already have the map screen created and working, I just wanted to put this map in alertDialog, but when I run I get this error message.

Process: scrcm.com.scrcmtecnico, PID: 4564
                                                                      java.lang.IllegalArgumentException: No view found for id 0x7f0b00b0 (scrcm.com.scrcmtecnico:id/fragmentFlutuante) for fragment MapsFragment{2cbffd1 #1 id=0x7f0b00b0 MapsFragment}
                                                                          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1293)
                                                                          at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                          at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                          at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                          at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                          at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                          at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                          at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
                                                                          at android.os.Handler.handleCallback(Handler.java:739)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

XML

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentFlutuante"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="scrcm.com.scrcmtecnico.activity.MapsFragment" />
    
asked by anonymous 02.10.2017 / 19:53

1 answer

0

Try to extend your MapsFragment class to DialogFragment

It would look like this:

MapsFragment

public class MapsFragment extends DialogFragment {

    private static View view;


    @Nullable
    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.mapa_flutuante, null);
        int width = getResources().getDimensionPixelSize(R.dimen.popup_width);
        int height = getResources().getDimensionPixelSize(R.dimen.popup_height);
        getDialog().getWindow().setLayout(width, height);



        return view;
    }

}

Call MapsFragment

 DialogFragment dialogFragment = new MapsFragment();
 FragmentManager fragmentManager = getSupportFragmentManager();
 dialogFragment.show(fragmentManager,"");
    
02.10.2017 / 20:20