
If (string.IsNullOrWhiteSpace(translatedNumber)) String translatedNumber = (phoneNumberText.Text) Translate user's alphanumeric phone number to numeric
#PRINT FROM ANDROID STUDIO IDE FILE MENU CODE#
TextView translatedPhoneWord = FindViewById(Resource.Id.TranslatedPhoneword) īutton translateButton = FindViewById(Resource.Id.TranslateButton) Īdd code that responds to user presses of the Translate button.Īdd the following code to the OnCreate method (after the linesĪdded in the previous step): // Add code to translate number OnCreate method, after the call to SetContentView: // Get our UI controls from the loaded layoutĮditText phoneNumberText = FindViewById(Resource.Id.PhoneNumberText)
#PRINT FROM ANDROID STUDIO IDE FILE MENU ANDROID#
Get a reference to the controls that were created in the layoutįile via the Android Designer. Set our view from the "main" layout resource Protected override void OnCreate(Bundle savedInstanceState) Public class MainActivity : AppCompatActivity Template code so that the OnCreate method resembles the following: using Android.App The next step is to add the button code inside OnCreate,īelow the base.OnCreate(savedInstanceState) and In the MainActivity class, find the OnCreate The next step is to add code to wire up the user interface by insertingīacking code into the MainActivity class. Save the changes to the PhoneTranslator.cs file by clickingįile > Save (or by pressing CTRL+S), then close the file. Static bool Contains (this string keyString, char c) otherwise we've skipped a non-numeric char Public static string ToNumber(string raw) Insert the following code into this file: using System.Text

In the Add New Item dialog, select Visual C# > Code > Code FileĪnd name the new code file PhoneTranslator.cs: Right-clicking the Phoneword project in the SolutionĮxplorer pane and choosing Add > New Item. The next step is to add some code to translate phone numbers fromĪlphanumeric to numeric. TextView to an empty string and set its Id property your work by pressing CTRL+S. Its Id property to a TextView from the Toolbox to the design surface and Properties pane to change its Text property to Translate and With the Button selected on the design surface, use the Surface and place it underneath the Plain Text widget: Use the Properties pane to change the Id property of theĭrag a Button from the Toolbox to the design

With the Plain Text widget selected on the design surface, Will appear as illustrated in the following screenshot: When the Plain Text (an EditText widget) is placed correctly, it Is moved just below the previous TextView (as shown on the right): Widget cannot be placed (as seen on the left) until the mouse pointer Widget will not occur until you move the mouse pointer to a place in The Text (Large) widget to Enter a Phoneword::ĭrag a Plain Text widget from the Toolbox to the design surfaceĪnd place it underneath the Text (Large) widget. Use the Properties pane to change the Text property of With the Text (Large) control selected on the design surface, You should change the tag to and add another attributeĪndroid:orientation="vertical" to the LinearLayout opening tag.įrom the Toolbox (the area on the left), enter text into the searchįield and drag a Text (Large) widget onto the design surface For the rest of the steps on this page to work

Newer releases of Visual Studio contain a slightly different app template.
