android fragment imports

0

I'm trying to load a map fragment and I have a problem with the imports:

If in the map fragment I import android.support.v4.app.Fragment, in the fragment from which I launched it, I get an error in the .replace because an argument of type android.app.Fragment is required.

Maps_fragment mapsf = new Maps_fragment();
            Bundle bundle = new Bundle();
            bundle.putString("latitud", instalacion.Latitud);
            bundle.putString("longitud", instalacion.Longitud);
            bundle.putString("titulo", instalacion.Nombre);
            bundle.putBoolean("editable", false);
            mapsf.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.flContenedor, mapsf).addToBackStack(null).commit();

However, if in the map fragment I import android.app.Fragment, it allows me to do the replace but I find the error "Inconvertible types; can not cast 'android.app.Fragment' to 'com.google.android. gms.maps.SupportMapFragment '"in the following line:

SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

Is there any way to load the fragment by being android.support.v4.app.Fragment or some other solution? Thanks!

    
asked by Juan 25.05.2018 в 10:58
source

2 answers

1

I solved it by changing SupportMapFragment () to MapFragment ()

    
answered by 25.05.2018 в 13:18
0

Juan, it is very important to know that using Fragments, in this case Maps, if you use getFragmentManager () to interact with Fragments , you should actually use MapFragment .

On the other hand, if you use support classes when getSupportFragmentManager () You must use SupportMapFragment .

    
answered by 25.05.2018 в 16:35