Skip to content

Instantly share code, notes, and snippets.

@InnovativeTechies
Created July 12, 2020 07:49
Show Gist options
  • Save InnovativeTechies/4f1670a653e5ba9b970bfcf0081065c3 to your computer and use it in GitHub Desktop.
Save InnovativeTechies/4f1670a653e5ba9b970bfcf0081065c3 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Chip;
using Android.Views;
using Android.Widget;
using Java.Lang;
using MaterialChipsDemo;
using MaterialChipsDemo.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(ChipsControl), typeof(ChipsViewRenderer))]
namespace MaterialChipsDemo.Droid
{
public class ChipsViewRenderer:Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<ChipsControl,Android.Support.Design.Chip.ChipGroup>
{
ChipGroup chipGroupLayout;
ChipsControl chipsControl;
Activity activity;
string chipText;
public ChipsViewRenderer(Context ctx) : base(ctx)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ChipsControl> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
chipsControl = e.NewElement as ChipsControl;
}
if (e.OldElement != null || Element == null)
{
return;
}
try
{
// chipText = chipsControl.ChipText;
SetupUserInterface();
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(@"ERROR: ", ex.Message);
}
}
private void SetupUserInterface()
{
try
{
activity = this.Context as Activity;
chipGroupLayout = (ChipGroup)LayoutInflater.From(Context).Inflate(Resource.Layout.ChipGroupXml, null);
string input = "hello world xamarin Forms";
var tags = input?.Split(" ");
foreach (var tag in tags)
{
var chip = (Chip)LayoutInflater.From(Context).Inflate(Resource.Layout.ChipItem, null);
chip.Text = tag;
chipGroupLayout.AddView(chip);
}
SetNativeControl(chipGroupLayout);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(@"ERROR: ", ex.Message);
}
}
//protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
//{
// base.OnElementPropertyChanged(sender, e);
// var control = sender as ChipsControl;
// chipText = control.ChipText;
// SetupUserInterface();
//}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment