I am trying below code but having errors..
'AdMobRenderer.OnElementChanged(ElementChangedEventArgs)': no suitable method found to override
'View' is an ambiguous reference between 'Xamarin.Forms.View' and 'Android.Views.View'
'AdMobRenderer.OnElementPropertyChanged(object, PropertyChangedEventArgs)': no suitable method found to override
The type or namespace name 'PropertyChangedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
Argument 1: cannot convert from 'Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.View>' to 'Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Samana.AdMobView>'
Kindly helpp....
here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Gms.Ads;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Samana.Droid;
using Samana;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobRenderer))]
namespace Samana.Droid
{
public class AdMobRenderer : ViewRenderer<AdMobView, AdView>
{
Context context;
public AdMobRenderer(Context _context) : base(_context)
{
context = _context;
}
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control == null)
SetNativeControl(CreateAdView());
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == nameof(AdView.AdUnitId))
Control.AdUnitId = Element.AdUnitId;
}
private AdView CreateAdView()
{
var adView = new AdView(Context)
{
AdSize = AdSize.SmartBanner,
AdUnitId = Element.AdUnitId
};
adView.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
adView.LoadAd(new AdRequest.Builder().Build());
return adView;
}
}
}
Kindly help....
Thanks,
Jassim