• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

how to access event of a control from another xml in main activity

babucr

Lurker
Nov 3, 2011
2
0
Hai

I have declared a button (BtnSave )in an xml file called defaultvalue

I want to access this control in main activity, Please tell me how to do this.

I use this code (C#)


thanks.

Main activity

publicclassActivity1 : Activity
{
protectedoverridevoidOnCreate(Bundlebundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
SetContentView(Resource.Layout.DefaultValue);
Buttonbutton = FindViewById<Button>(Resource.Id.Btn_Default);
ButtonBtnsave = FindViewById<Button>(Resource.Id.BtnSave);



button.Click += delegate
{
varRatio = newAlertDialog.Builder(this);
Ratio.SetView(LayoutInflater.Inflate(Resource.Layout.DefaultValue ,null));
Ratio.SetTitle("Select Ratio");
Ratio.Create().Show();
Toast.MakeText(this, "you clicked on " ,
ToastLength.Short).Show
();
};


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();
Ratioc.Create().Dismiss();
};
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones