Supportmapfragment On Dialogfragment
I need to embed aSupportMapFragmentin aDialog. This is the best I could think of: public class SupportMapFragmentDialog extends DialogFragment { private final SupportMapFragme
Solution 1:
You can show a map fragment in a dialog by this
publicclassDialogMapFragmentextendsDialogFragment {
private SupportMapFragment fragment;
publicDialogMapFragment() {
fragment = newSupportMapFragment();
}
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Viewview= inflater.inflate(R.layout.mapdialog, container, false);
getDialog().setTitle("");
FragmentTransactiontransaction= getChildFragmentManager().beginTransaction();
transaction.add(R.id.mapView, fragment).commit();
return view;
}
public SupportMapFragment getFragment() {
return fragment;
}
}
R.layout.mapdialog:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="0dp" ><FrameLayoutandroid:id="@+id/mapView"android:layout_width="match_parent"android:layout_height="match_parent" ></FrameLayout></RelativeLayout>Solution 2:
In the end I ended up usingMapViewin a regularDialoginstead ofSupportMapFragment
This is my code:
finalHistoricoh= adapter.getItem(arg2 - 1);
if (mv.getParent() != null) {
((ViewGroup) mv.getParent()).removeView(mv);
}
finalDialogd=newDialog(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));
finalMarkerOptionsoptions=newMarkerOptions();
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
options.position(h.getPosicion());
mv.getMap().addMarker(options);
d.show();
And it works as intended.
Post a Comment for "Supportmapfragment On Dialogfragment"