android中寻呼机片段内部有映射的对话框

android中寻呼机片段内部有映射的对话框,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,我正在开发应用程序,并从对话框内部的对话框布局文件中获取访问片段的错误null。实际上,我想在一个对话框中显示地图,点击页面片段中的列表视图 对话框布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map_view" android:layout_width=

我正在开发应用程序,并从对话框内部的对话框布局文件中获取访问片段的错误null。实际上,我想在一个对话框中显示地图,点击页面片段中的列表视图

对话框布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    android:id="@+id/mapevent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Close"
    android:id="@+id/close"
    android:background="@null"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

片段文件和我附加对话框的对话框。它的工作,而我试图让地图对象添加标记,然后我并没有得到支持地图碎片的对象

public class Event extends Fragment {
private ListView listView;
.
.
.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item_three, container, false);
   if(map_dialog==null)
    map_dialog= new Dialog(getActivity());

    listView = (ListView) view.findViewById(R.id.event_list);
    dialog.show();
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
           dialog.show();

            map_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            map_dialog.setContentView(R.layout.dialog_layout);
            map_dialog.show();

            MapsInitializer.initialize(getActivity());
            FragmentManager myFragmentManager = getActivity().getSupportFragmentManager();
             mMapView = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
            mMapView.onCreate(map_dialog.onSaveInstanceState());
            mMapView.onResume();// needed to get the map to display immediately
            mMapView.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap googleMap) {

                    latLng=new LatLng(Double.parseDouble(eventList.get(position).getLat()),Double.parseDouble(eventList.get(position).getLng()));
                    googleMap.addMarker(new MarkerOptions().position(latLng));
                    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
                    dialog.dismiss();
                }
            });
        }
    });
公共类事件扩展片段{
私有列表视图列表视图;
.
.
.
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图=充气机。充气(R.layout.fragment\u item\u three,容器,错误);
if(map_dialog==null)
map_dialog=新建对话框(getActivity());
listView=(listView)view.findViewById(R.id.event\u list);
dialog.show();
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、最终整型位置、长id){
dialog.show();
映射对话框。请求窗口功能(窗口。功能\u无\u标题);
map_dialog.setContentView(R.layout.dialog_layout);
map_dialog.show();
初始化(getActivity());
FragmentManager myFragmentManager=getActivity().getSupportFragmentManager();
mMapView=(SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
mMapView.onCreate(map_dialog.onSaveInstanceState());
mMapView.onResume();//需要立即显示地图
mMapView.getMapAsync(新的OnMapReadyCallback(){
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
latLng=new-latLng(Double.parseDouble(eventList.get(position.getLat()),Double.parseDouble(eventList.get(position.getLng());
addMarker(新的MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
dialog.dismise();
}
});
}
});

试试这个:

FragmentManager myFragmentManager = getActivity().getSupportFragmentManager();
mMapView = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.mapevent);
对于对话框,您可以使用
MapView
而不是
SupportMapFragment

<com.google.android.gms.maps.MapView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:id="@+id/map" />

不工作我已经检查过了你刚刚更改了Id实际上我忘记写了,但我两边都使用了相同的Id。但是感谢您的努力MapView=(MapView)map_dialog.findViewById(R.Id.map);发布崩溃日志。。。。
MapView mMapView;


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

        dialog.show();

        map_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        map_dialog.setContentView(R.layout.dialog_layout);
        map_dialog.show();

        mMapView = (MapView) map_dialog.findViewById(R.id.map);
        mMapView.onCreate(map_dialog.savedInstanceState);
        mMapView.onResume();// needed to get the map to display immediately

        try {
            MapsInitializer.initialize(this.getActivity());
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {

                latLng = new LatLng(Double.parseDouble(eventList.get(position).getLat()),Double.parseDouble(eventList.get(position).getLng()));
                googleMap.addMarker(new MarkerOptions().position(latLng));
                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
                dialog.dismiss();
            }
        });
    }
});