【问题标题】:Can't cast from Android.Support.V4.App.Fragment to SupportMapFragment无法从 Android.Support.V4.App.Fragment 转换为 SupportMapFragment
【发布时间】:2014-03-16 17:08:20
【问题描述】:

我处于一种奇怪的情况,我无法将 Fragment 转换为 SupportMapFragment。而且我已经阅读了 8+ 个关于类似问题的主题,这些主题都与我的问题无关。他们都混合了 MapFragment 和 SupportMapFragment,或者引用了 Android.App 而不是 Android.Support.V4.App。

我在 Mono (MvvmCross) 中。我的布局包含一个 SupportMapFragment。

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

所以,下面是我尝试从布局中获取 SupportMapFragment 的方法:

var theMap =  (SupportMapFragment) SupportFragmentManager
                                  .FindFragmentById(Resource.Id.map);

Cannot cast expression of type 'Android.Suport.V4.App.Fragment'
to type 'SupportMapFragment'

SupportMapFragment 继承自 android.support.v4.app.Fragment,所以我觉得它很奇怪。

我引用了 Mono.Android.Support.v4Xamarin.Android.Support.V4

我注意到我的 SupportFragmentManager 来自 global::Android.Support.V4.App,而不是前面提到的两个程序集。

我的项目针对 API 13 到 19,并在 API 19 中编译。

我正在使用 Cirrious.MvvmCross.Droid.Fragging 的预编译版本,因为组件中的版本无法构建。

简而言之:我从SupportFragmentManager 得到的不能转换为SupportMapFragment

【问题讨论】:

    标签: xamarin.android supportmapfragment


    【解决方案1】:

    虽然我不想回答我自己的问题,但这个问题非常有问题,我将贡献于记录解决方法。为了让它发挥作用,我:

    • 添加了 GooglePlayServices 组件
    • 添加了 Android Support V4 组件
    • 添加了 Cirrous.MvvmCross.Droid.Fragging 的原始源代码
    • 确保我只添加引用的 Xamarin.Android.Support.V4 而不是 Mono.Android.Support.V4

    它现在可以在没有任何程序集重定向的情况下工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 2013-03-21
      相关资源
      最近更新 更多