【问题标题】:MapFragment Inflated Activate Through EditTextMapFragment Inflated 通过 EditText 激活
【发布时间】:2016-09-21 05:39:26
【问题描述】:

我在为地图充气时遇到问题。起初如果我点击EditText,它会启动,如果我取消/确定AlertDialog.Builder,然后再次点击EditText,它会导致:

E/MapError: android.view.InflateException: Binary XML file line #10: Error inflating class fragment

逻辑是:我已经完成了地区和省。通过MapFragment 中的地区和省来设置所选地区和省的相机位置,这是我除了 MapError 之外唯一的问题。

我的Map代码:

//START MAP FRAGMENT DIALOG
public void alertOrgMapSetMarker(){

    LayoutInflater layoutInflater = getLayoutInflater();
    View getView = layoutInflater.inflate(R.layout.map_inflate_org,null);
                   mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment_org);

    AlertDialog.Builder alertMap = new AlertDialog.Builder(AdminCreateEventActivity.this,R.style.AlertDialogCustom);
    alertMap.setTitle("Mark Location")
            .setView(getView)
            .setCancelable(false)
            .setPositiveButton("Set", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    AlertDialog mapDialog = alertMap.create();
    mapDialog.show();
}

这行代码我不能getView。为了有控制权。我要@Override -setMapClickListener

mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment_org);

我的膨胀 XML:map_inflate.xml

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"
    android:id="@+id/map_fragment_org"
    map:cameraBearing="112.5"
    map:cameraTargetLat="10.3157"
    map:cameraTargetLng="123.8854"
    map:cameraTilt="45"
    map:cameraZoom="30"
    map:mapType="normal"
    map:uiCompass="true"
    map:uiRotateGestures="true"
    map:uiScrollGestures="true"
    map:uiTiltGestures="true"
    map:uiZoomControls="true"
    map:uiZoomGestures="true"
    tools:ignore="MissingPrefix"/>

我真的需要你的帮助。谢谢。

【问题讨论】:

  • AdminCreateEventActivity 扩展FragmentActivity 还是simple Activity
  • @M D:你在想SupportMapFragment的问题吗?
  • extends AppCompatActivity.
  • @RoCk 尝试扩展FragmentActivity 或使用SupportMapFragment
  • 我会试试你建议的答案。我会通知它是否有效。 :)

标签: android android-alertdialog mapfragment


【解决方案1】:

我建议使用MapView 作为片段内的地图:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

</FrameLayout>

【讨论】:

  • 我不这么认为。您可以在Fragment 内使用任何MapFragmentSupportMapFragment
  • 如果我更改我的MapFragment,我现在可以在我的视图中使用getView了吗?
  • 我的地图不见了 :( 我会为我的错误发布一个屏幕截图
猜你喜欢
  • 2015-01-05
  • 2010-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-14
  • 2020-03-27
相关资源
最近更新 更多