I have a custom class that inherits from GridLayout. One of the elements contained in the xml layout file is an EditText, and I want to be able to handle the EditText's FocusChange event. I figured the best way to do this would be to bubble the EditText's FocusChange event up to the GridLayout's FocusChange event. However, I cannot figure out how to do this. Here is my current code:
public class NamesPlayer : GridLayout
{
public string Name { get; set; }
public string DefaultName { get; set; }
public NamesPlayer(Context context) : base(context) { this.Initialize(context); }
public NamesPlayer(Context context, IAttributeSet attrs) : base(context, attrs) { this.Initialize(context, attrs); }
public NamesPlayer(Context context, IAttributeSet attrs, int defstyleattrs) : base(context, attrs, defstyleattrs) { this.Initialize(context, attrs); }
public NamesPlayer(Context context, IAttributeSet attrs, int defstyleattrs, int defstyleres) : base(context, attrs, defstyleattrs, defstyleres) { this.Initialize(context, attrs); }
void Initialize(Context context, IAttributeSet attrs = null)
{
Inflate(context, Resource.Layout.NamesPlayer, this);
ImageButton btnPlayer = FindViewById<ImageButton>(Resource.Id.btnPlayer);
EditText txtPlayer = FindViewById<EditText>(Resource.Id.txtPlayer);
btnPlayer.Click += (object sender, System.EventArgs e) => { this.CallOnClick(); };
//txtPlayer.FocusChange += this.txtPlayer_FocusChange;
if (attrs != null)
{
TypedArray ta = context.ObtainStyledAttributes(attrs, Resource.Styleable.NamesPlayer);
txtPlayer.Text = ta.GetString(Resource.Styleable.NamesPlayer_Name);
txtPlayer.Hint = ta.GetString(Resource.Styleable.NamesPlayer_DefaultName);
ta.Recycle();
}
}
private void txtPlayer_FocusChange(object sender, FocusChangeEventArgs e) { }
}