Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to create a button event handler from the gui in Visual Studio for an Android(Xamarin) project?

In the default New Project for Android (Xamarin) in Visual Studio, you get a Hello World screen and kind of a button.
Coming from WPF, I dragged a Button out of the Toolbox into activity_main.xml which is where the original button is.

In Properties, Behavior, On Click, I added the name of a desired handler which populates the xml as shown below.

In MainActivity.cs (which I presume is comparable to the code behind) I put in what I found on the web to be how Android expects click handlers:
public void Button1_Click(View view) etc.

and set a breakpoint here. When Run, the button appears, if I click it, the app crashes with an exception:
Java.Lang.IllegalStateException: 'Loading...'

and VS just sits there at that point.

How do you specify the handler from the GUI so that this works. Why is the handler not like typical MS button handlers that include Sender and EventArgs?

Best Answer


  • chrisbaumgartnerchrisbaumgartner USMember ✭✭

    this forum doesnt seem to like posting code. It seems to blow up the entry page. So I cant post the .xml I guess. But you get the idea, its just the block where the gui makes the xml.

Sign In or Register to comment.