MapFragment support on DialogFragment

I need to insert SupportMapFragment in Dialog . This is the best I could think of:

 public class SupportMapFragmentDialog extends DialogFragment { private final SupportMapFragment fragment; public SupportMapFragmentDialog() { fragment = new SupportMapFragment(); setTargetFragment(fragment, 1); } @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { return fragment.onCreateView(inflater, container, savedInstanceState); } public SupportMapFragment getFragment() { return fragment; } } 

However, when I call it:

 final SupportMapFragmentDialog dialog = new SupportMapFragmentDialog(); dialog.show(getSupportFragmentManager(), "Historico"); 

I get this:

enter image description here

What can I do to see the map in the dialog?

There is another SupportMapFragment in the application that works wonders, so it has nothing to do with configuration.

+4
source share
2 answers

I ended up using MapView in a regular Dialog instead of SupportMapFragment

This is my code:

 final Historico h = adapter.getItem(arg2 - 1); if (mv.getParent() != null) { ((ViewGroup) mv.getParent()).removeView(mv); } final Dialog d = new Dialog(HistorialScreen.this); d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(mv); mv.getMap().clear(); mv.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(h.getPosicion(), 17)); final MarkerOptions options = new MarkerOptions(); options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)); options.position(h.getPosicion()); mv.getMap().addMarker(options); d.show(); 

And he works as intended.

+1
source

You can show a fragment of the map in the dialog with this

 public class DialogMapFragment extends DialogFragment { private SupportMapFragment fragment; public DialogMapFragment() { fragment = new SupportMapFragment(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.mapdialog, container, false); getDialog().setTitle(""); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.add(R.id.mapView, fragment).commit(); return view; } public SupportMapFragment getFragment() { return fragment; } } 

R.layout.mapdialog:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="0dp" > <FrameLayout android:id="@+id/mapView" android:layout_width="match_parent" android:layout_height="match_parent" > </FrameLayout> </RelativeLayout> 
+12
source

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


All Articles