Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SupportMapFragment on DialogFragment

I need to embed aSupportMapFragmentin aDialog. 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 this:

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

I get this:

enter image description here

What can I do to see the map on the Dialog?

The app has another SupportMapFragment that is working wonders, so it doesn't have anything to do with the configuration.

like image 392
Charlie-Blake Avatar asked Dec 11 '22 14:12

Charlie-Blake


1 Answers

You can show a map fragment in a dialog by 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>
like image 72
kmangr Avatar answered Dec 21 '22 11:12

kmangr