Like in the iPhone project, add a reference to the WebServiceAccess.dll library in the project. For simplicity, you are finding the exchange rate between the US Dollars and the Euro. The first argument to the UIAlertView’s constructor is the title of the pop-up.
You can also click on the Source tab located at the bottom of the designer to switch to the editor that allows you to directly modify the UI of the activity using XML. The project has been created (as shown in Figure 4). You can see that the application delegate (AppDelegate.cs) is selected. Xamarin also recognizes that beyond the surface (user interface), apps have a lot of highly reusable components that can be shared across platforms. For example, your code for accessing Web services can be reused easily on the iOS and Android platforms.
Running your Xamarin app on an Android emulator
On the above screen, supply the AVD name you want. Select a device that is appropriate for your display, e.g., Nexus 4” display. It is always advisable to test on a minimum target platform, e.g., API 10 Android 2.3 (Gingerbread) so as to ensure your App works across all Android platforms. Build and then run it to display the created app in an Android Emulator. Back in the Android Virtual Device Manager dialog box, select the AVD that you have just created and click Start… Click Launch to launch the AVD (see Figure 20).
Under the .Net Assembly tab, navigate to the ~/Projects/WebServiceAccess/WebServiceAccess/bin/Debug/ folder and double-click on the WebServiceAccess.dll and then click OK. This adds the class library to the project so that you can use it for accessing the currency convertor Web service. The second type of apps, Web-apps, are applications that run off the Web browser.
Understanding the new solution
Before you can test the application on the Android Emulator (known as an Android Virtual Device), you need to create one. Now that you have seen how things work in Xamarin.iOS, it’s time to move to the other world and explore Xamarin.Android, that allows you to develop Android apps. Click on the Run button in Xamarin Studio to deploy the application onto the iPhone Simulator. When the application is loaded, enter your name and click the OK button (see Figure 12).
For the Framework, select “.NET 2.0 Web Services” and click OK. Right-click on the project name and select Add | Add Web Reference (see Figure 24). Using https://wizardsdev.com/en/news/new-mobile-course/ Xamarin, create a new C# Library project (see Figure 23). For this example, switch to the Source editor and enter the XML directly, as shown in Listing 3.
Customizing the appearance of your app
As you can see, the coding that you have done is all for the UI. So far, there is really no benefit to using Xamarin apart from using the C# language instead of using Objective-C for iOS and Java for Android. Well, the following example is going to show you the true benefits of using Xamarin.
The HelloiPhoneViewController.designer.cs contains code that is pertinent to the View window of the View Controller. Double-click on it and you can see that the some statements (Listing 1) are added in automatically for you. Back in Xamarin Studio, expand the HelloiPhoneViewController.cs item by clicking on the arrow icon displayed next to it. This reveals the item named HelloiPhoneViewController.designer.cs (see Figure 11). The part of Xamarin that allows you to develop iOS apps is called Xamarin.iOS.
It is important to realize what Xamarin is not; it is not a “write once and run everywhere” tool for your mobile development. Instead, Xamarin respects that each platform has its own unique features, and that apps on each platform behave differently. However, business logics are highly reusable and this is where Xamarin shines. With the iPhone version tested working correctly, let’s now open up the HelloAndroid project that you created earlier.
When you click on either the OK or Cancel button, the pop-up is dismissed. You can view the output that is printed by your application by selecting View | Pads | Application Output in Xamarin Studio. Control-click the button and drag it over the code editor. This time, change the Connection to Action and name it btnOK (see Figure 10).
Building Your First Mobile App with C# .NET and Xamarin
In this article, I provide an introduction to Xamarin and its appeal to developers who are building cross-platform mobile apps. In the above code, we have created a new Android textview. Next, open the folder values and double-click Strings.xml to open it. Here, we are going to store information and values about the button created above. In this article, you have seen what it is like to develop iOS and Android apps using Xamarin.
- Now that the class library is built, it is time to test it on both the iPhone and Android projects to see if Xamarin really lives up to its promises.
- The only difference is that in Android, you use the RunOnUiThread() method to display the Toast window in the main UI thread.
- Open up the HelloiPhone project that you have created earlier and double-click on the References item in the solution (see Figure 26).
- Control-click the button and drag it over the code editor.
Xamarin is a software company based in San Francisco. It provides commercial software development tools that allow a user to develop applications for Android, iOS and Windows using C# language and the .NET framework. It allows one to create apps that easily run across multiple platforms. In this tutorial, we will explain how you can use Xamarin to deliver native iOS, Android, and Windows Apps. Now that the class library is built, it is time to test it on both the iPhone and Android projects to see if Xamarin really lives up to its promises. Open up the HelloiPhone project that you have created earlier and double-click on the References item in the solution (see Figure 26).