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 same for all the platforms. Xamarin also helps us by providing the designers 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 for both Windows or Mac. Visual Studio supports only in Windows, provided you can build and debug on Mac.
Prerequisites
The following steps are required to follow in order to create Timer Task in Xamarin.Forms in VS 2017.
Step 1
Goto the Visual Studio
On File menu>>New>> Project
Click on C#>>Select Android>> Then select Blan App(Android)
Enter the Application Name, Click ok.
Now You can see the Home page of the project.
Step 2
In this step we are going create 3 buttons and Label’s for timer display
Step 3
In this step we going to give the Start button click event and Pause button Click 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 give 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. Thank You.