Map Fragment OnResume功能代码

时间:2014-04-07 06:46:48

标签: android android-fragments xamarin onresume mapfragment

在Xamarin中,我正在修改一个标准Activity的类,但现在是Map Fragment。继承的Map Fragment属于Android.Support.V4.App.Fragment

以下是上一段代码:

protected override void OnPause()
{
    base.OnPause();

    // Pause the GPS - we won't have to worry about showing the 
    // location.
    _map.MyLocationEnabled = false;

    _map.InfoWindowClick -= HandleInfoWindowClick;
    _map.MarkerClick -= HandleMarkerClick;

    //_map.MarkerClick -= MapOnMarkerClick;
}

protected override void OnResume()
{
    base.OnResume();
    SetupMapIfNeeded();

    _map.MyLocationEnabled = true;

    _map.InfoWindowClick += HandleInfoWindowClick;
    _map.MarkerClick += HandleMarkerClick;

    // Setup a handler for when the user clicks on a marker.
    //_map.MarkerClick += MapOnMarkerClick;
}

这是我正在使用的代码:

protected override void Android.Support.V4.App.Fragment.OnPause()
{
    base.OnPause();

    // Pause the GPS - we won't have to worry about showing the 
    // location.
    _map.MyLocationEnabled = false;

    _map.InfoWindowClick -= HandleInfoWindowClick;
    _map.MarkerClick -= HandleMarkerClick;

    //_map.MarkerClick -= MapOnMarkerClick;
}

protected override void Android.Support.V4.App.Fragment.OnResume()
{
    base.OnResume();
    SetupMapIfNeeded();

    _map.MyLocationEnabled = true;

    _map.InfoWindowClick += HandleInfoWindowClick;
    _map.MarkerClick += HandleMarkerClick;

    // Setup a handler for when the user clicks on a marker.
    //_map.MarkerClick += MapOnMarkerClick;
}

我的两种方法都出错了。这是错误:

Error CS0106: The modifier 'override' is not valid for this item

我可以帮助编写这些函数吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

如果您正在使用片段和V4支持库,则需要:

  • 安装Google Play服务(Gingerbread)或(Froyo)套餐
  • 您的片段应继承自SupportMapFragment
  • 确保您在“应用程序”标签下的“项目属性”中定位API级别8

请勿安装通用Google Play服务组件,因为它不提供SupportMapFragment

然后它应该工作。