access click event of button declared in xml file

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Aug 3, 2014 7:17:15 PM via Website

I am using C# as language in vs 2010 and I am new to android.

I have created an xml file with three text box and two button.
I want to know how to access this button event and values of editText from main activity.

I use this code and I don't know weather it is correct.

public class Activity1 : Activity
protected override void OnCreate(Bundle bundle)



        Button button = FindViewById<Button>(Resource.Id.Btn_Default);
        Button Btnsave = FindViewById<Button>(Resource.Id.BtnSave);

        button.Click += delegate
           var Ratio = new AlertDialog.Builder(this);
           Ratio.SetView(LayoutInflater.Inflate(Resource.Layout.DefaultValue  ,null));
           Ratio.SetTitle("Select Ratio");

        Btnsave.Click += (sender, e) => 
             var Ratioc = new AlertDialog.Builder(this);
             Ratioc.SetView(LayoutInflater.Inflate(Resource.Layout.DefaultValue, null));
            Toast.MakeText(this, "you clicked on " + Btnsave.Text, ToastLength.Long).Show();


My Xml File name is DefaultValue and Btnsave is the button
when I run without Btnsave.Click event then program runs but with this it not running

— modified on Aug 3, 2014 7:19:08 PM

  • Forum posts: 19

May 7, 2015 11:30:43 PM via Website


a simple attribute