Xamarin Introduction
Xamarin is the best cross platform tool to develop mobile applications. It provides cross platform app development in C#, so we don’t need to write in Java or Objective C. We can just use C# and leverage the benefits on all the platforms. Xamarin also helps designers by providing with the different platforms like Android, iOS, etc.
Working with Xamarin Application Development, we have two gateways- Xamarin Studio and Visual Studio. Xamarin Studio supports both, Windows or Mac. Visual Studio supports only Windows, provided, you can build and debug the application on Mac.
Prerequisites
The following steps are required to be followed in order to create StopWatch application in Xamarin.Forms using VS 2017.
Step 1
Go to the Visual Studio, File >> New >> Project.
Click on C# >> Android >> Blank App(Android).
Enter the application name and click OK.
Now, you can see the homepage of the project.
Step 2
In this step, we are going create 3 buttons and labels for displaying timer.
Step 3
In this step, give the code for Start button click event and Pause button click event in MainActivity.cs.
- btnStart.Click += delegate {
- timer = new Timer();
- timer.Interval = 1;
- timer.Elapsed += Timer_Elapsed;
- timer.Start();
- };
- btnPasuse.Click += delegate {
- timer.Stop();
- timer = null;
- };
Step 4
In this step, assign the Timer_Elapsed to timer label.
Step 5
In this step, write code for Lap button click event.
- btnLap.Click += delegate {
- LayoutInflater inflater = (LayoutInflater) BaseContext.GetSystemService(Context.LayoutInflaterService);
- View addView = inflater.Inflate(Resource.Layout.row, null);
- TextView txtContent = addView.FindViewById < TextView > (Resource.Id.textView1);
- txtContent.Text = txtTimer.Text;
- container.AddView(addView);
- };
Step 6
Run the app.
I hope this article is very useful.