Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

how to SetOnClickListener in FrameRenderer?

$
0
0

I have that code below works for button but i would like to change button to frame.
Does anybody know how to convert it? I cant figure out SetOnClickListener part as it is not exist in framerenderer?

using System;
using Android.App;
using Android.Content;
using Xamarin.Forms.Platform.Android;
using Object = Java.Lang.Object;
using View = Android.Views.View;
using Xamarin.Facebook;
using Android.Widget;
using myApp.Authentication;
using myApp.Droid.Authtentication;

[assembly: Xamarin.Forms.ExportRenderer(typeof(FacebookLoginButton), typeof(FacebookLoginButtonRendererAndroid))]
namespace myApp.Droid.Authtentication
{
    public class FacebookLoginButtonRendererAndroid : ButtonRenderer
    {
        private static Activity _activity;
        Context _Context;
        public FacebookLoginButtonRendererAndroid(Android.Content.Context context)
                 : base(context)
        {
            _Context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            _activity = _Context as Activity;

            //DEBUG
            //Xamarin.Facebook.Login.LoginManager.Instance.LogOut();

            if (this.Control != null)
            {
                Button button = this.Control;
                button.SetOnClickListener(ButtonClickListener.Instance.Value);
            }

            if (AccessToken.CurrentAccessToken != null)
            {
                App.PostSuccessFacebookAction(AccessToken.CurrentAccessToken.Token);
            }
        }

        private class ButtonClickListener : Object, IOnClickListener
        {
            public static readonly Lazy<ButtonClickListener> Instance = new Lazy<ButtonClickListener>(() => new ButtonClickListener());

            public void OnClick(View v)
            {
                var myIntent = new Intent(_activity, typeof(FacebookActivity));
                _activity.StartActivityForResult(myIntent, 0);
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>