Introduction
In this article, we will learn how to build Call Translator App for Xamarin Android. This is a simple app for learning some basics for beginners and you can also create it in Android Studio but I like to make it in Visual Studio, therefore, I developed it in Xamarin. I will use C# language for logical code and AXML for layout. I used the name Call Translator, which means if you are not using QWERTY keyboard on your mobile phone and you type A, or B, or C, it will be considered as number 2 and if you type D, or E, or F, it will be considered as number 3 and so on. This app will convert your alphabets to numbers. Simply click on the "Translate" button for converting and after converting, you can call on the converted numbers.
Step 1
Create/ open your Android solution in Visual Studio or Xamarin Studio. Select Android and from the list, choose Android Blank App.
Step 2
First of all, we need TextView for showing a message and TextEdit for writing the text. There are two buttons for Translating and for Calling, so go to the Solution Explorer and open the Resources folder.
(File Name: Main.axml)
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:text="Enter a Phone Number"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView" />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/phoneNumberText"
- android:text="+92300-Ahsan" />
- <Button
- android:text="Translate"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/btnTranslate" />
- <Button
- android:text="Call"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/btnCall" />
- </LinearLayout>
The designed from will look like below.

Step 3
Now, create a new class in this Solution as CallTranslator for Call Translator and in this class, define a method of translating the calls.
(FileName: CallTranslator.cs)
- public static class CallTranslator
- {
- public static string ToNumber(string raw)
- {
- if (string.IsNullOrWhiteSpace(raw))
- return "";
- else
- {
- raw = raw.ToUpperInvariant();
- }
- var newNumber = new StringBuilder();
- foreach (var c in raw)
- {
- if (" -0123456789".Contains(c))
- newNumber.Append(c);
- else
- {
- var result = TranslateNumber(c);
- if (result != null)
- newNumber.Append(result);
- }
- }
- return newNumber.ToString();
- }
- static bool Contains(this string KeyString, char c)
- {
- return KeyString.IndexOf(c) >= 0;
- }
- private static int? TranslateNumber(char c)
- {
- if ("ABC".Contains(c))
- return 2;
- else if ("DEF".Contains(c))
- return 3;
- else if ("GHI".Contains(c))
- return 4;
- else if ("JKL".Contains(c))
- return 5;
- else if ("MNO".Contains(c))
- return 6;
- else if ("PQR".Contains(c))
- return 7;
- else if ("STUV".Contains(c))
- return 8;
- else if ("WXYZ".Contains(c))
- return 9;
- return null;
- }
- }


Join the conversation! Your thoughts help the community grow.