I've just started learning about Xamarin Android. I've got few buttons with the same click event handler.
private Button flipper1Btn;
private Button flipper2Btn;
private ViewFlipper flipper;
private TextView text;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
setControls();
setEvents();
}
private void setControls()
{
flipper = FindViewById<ViewFlipper>(Resource.Id.viewFlipper1);
flipper1Btn = FindViewById<Button>(Resource.Id.button1);
flipper2Btn = FindViewById<Button>(Resource.Id.button2);
text = FindViewById<TextView>(Resource.Id.textView1);
}
private void setEvents()
{
flipper1Btn.Click += FlipperBtn_Click;
flipper2Btn.Click += FlipperBtn_Click;
}
#region Events
private void FlipperBtn_Click(object sender, EventArgs e)
{
Button sendBtn = (Button)sender;
}
#endregion
In "FlipperBtn_Click" method I would like to recognize which button was pressed and get value from this button. I would like to achieve something like in HTML5 by assign to div as many attribute I want. I was thinking about android "Tag" propertie, and trying to do something like this:
private void setControls()
{
flipper = FindViewById<ViewFlipper>(Resource.Id.viewFlipper1);
flipper1Btn = FindViewById<Button>(Resource.Id.button1);
flipper2Btn = FindViewById<Button>(Resource.Id.button2);
text = FindViewById<TextView>(Resource.Id.textView1);
FlipperBtnTag tag1 = new FlipperBtnTag("tag1", "tag1Value");
FlipperBtnTag tag2 = new FlipperBtnTag("tag2", "tag2Value");
flipper1Btn.SetTag(1, tag1);
flipper1Btn.SetTag(2, tag2);
}
Bud I don't understand few thinks: a) What is a purpose of using "key" in SetTag method? b) How Can I convert c# class object into Java.Lang.Object?