[Xamarin – Android] Create Hello World

Recently when i open internet i often see ad about Xamarin, and i think about do an android project with this software. Okey, im very new learn about xamarin. But i think its good to share what i learn about xamarin.

Xamarin’s not free, but as starter you can use it for free. See this link to know about license https://store.xamarin.com/. If its not free, why you must use this? I dont know, but i want to know how C# performance when run android apps and for now i just interest with this tools, but you can see here http://xamarin.com/how-it-works to know why you must use xamarin.

The first think i learn (and always in other programming learn) is how to create hello world app.

– After you installed xamarin, open your xamarin studio.

– Select “new”, and in “C#” menu you must select “Android” menu and select “Android Application” (dont forget to set application name). Select “OK”.

– In your project, open “MainActivity.cs”. You will see this code :

  [Activity (Label = "hello", MainLauncher = true)]  // define this activity is launch activity
     public class MainActivity : Activity  // define class
     {
         int count = 1;

         protected override void OnCreate (Bundle bundle)  // define function when activity create
         {
             base.OnCreate (bundle);

             // Set our view from the "main" layout resource
             SetContentView (Resource.Layout.Main);

             // Get our button from the layout resource,
             // and attach an event to it
             Button button = FindViewById<Button> (Resource.Id.myButton);

             button.Click += delegate {
                 button.Text = string.Format ("{0} clicks!", count++);
             };
         }
     }

That code will show  a button and when you click the button will show total click you click. Where the button come from? see code in “Resource/layout/Main.axml”. So change that code like this :

  [Activity (Label = "hello", MainLauncher = true)]
     public class MainActivity : Activity
     {
         protected override void OnCreate (Bundle bundle)
         {
             base.OnCreate (bundle);

             // Set our view from the "main" layout resource
             SetContentView (Resource.Layout.Main);

             // Get our button from the layout resource,
             // and attach an event to it
             Button button = FindViewById<Button> (Resource.Id.myButton);

             button.Click += delegate {
                 button.Text = string.Format ("Hello World");
             };
         }
     }

save it..
Run your application.. you will see this :1

2Finish… hope it help..

Happy coding…

One Response to [Xamarin – Android] Create Hello World

  1. Pingback: [Xamarin - Android] Work With Multi Activity | Sabitlabscode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: