Download Code

Xamarin EditText Example Android

In this tutorial you will learn how to use Xamarin EditText Example android application.Also some basic information about Text Fields and Input Controls.

Input Controls

Input Controls are the interactive app UI components.Android provide some controls like

  • Button
  • Text Fields
  • Check Box
  • Radio
  • Spinner
  • Seek bar
  • Pickers

Text Fields

Text Field allows the user to type text in android application.Text Field can be single line or multiple line.For example Edit Text.There are some different types of Edit Text.

  • Plain Text
  • Person Name
  • Password
  • Email
  • Postal Address
  • Phone
  • Time
  • Date

Now let’s talk about Edit Text.

Xamarin EditText

basically used to take user input for any particular purpose.Subclass of Text View which turned itself into Edit Text.

So you will code for edit text and display in Toast on button click what user will input in that edit text.

Let’s start go ahead and create android application project.

Go to your Main.xml file and add Edit Text and button UI component.

xamarin edittext,xamarin edittext example,xamarin edittext example android,edittext example android

 

Now go to your MainActivity.cs class.Add variables for button,Edit Text.Then refer id’s and apply click event.At last add Toast within click event of button.

MainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;

namespace Edittext
{
	[Activity (Label = "Edittext", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity : Activity
	{
		
		EditText userTxt;    // edit text variable
		Button displayBtn;   // button variable
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);
			initialize ();   // method to get all id's of UI componenet
			displayBtn.Click += DisplayBtn_Click;  // applying click event on button
			 
		}
		//click method
		void DisplayBtn_Click (object sender, System.EventArgs e)
		{
			Toast.MakeText (this, userTxt.Text.ToString(), ToastLength.Short).Show ();   // displaying toast
		}
		// method to refer all UI component's
		public void initialize(){
			userTxt = FindViewById< EditText > (Resource.Id.editText1);
			displayBtn = FindViewById< Button > (Resource.Id.myButton);
		}
	}
}


Now Run your xamarin edittext example android application project.

xamarin edittext,xamarin edittext example,xamarin edittext example android,edittext example android

that’s it for xamarin edittext example android tutorial.

Thanks