Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
EditTextDemo
Images reorganizing files into recipes folder Mar 7, 2018
EditTextDemo.sln
README.md Adding absolute link to guides Mar 29, 2018

README.md

id title brief article sdk
EC009100-EAE0-0BDA-3AC9-60BBF78854EB
Capture User Input Text
This recipe shows how to use EditText control to capture text entered by a user.

Recipe

  1. Create a new Xamarin.Android application named EditTextDemo.
  2. In Main.xml to include an EditText and a TextView.
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

    <EditText

        android:id="@+id/editText"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"/>

    <TextView

        android:id="@+id/textView"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"/>  

</LinearLayout>
  1. In MainActivity.cs, get references to the EditText and the TextView.
var editText = FindViewById<EditText> (Resource.Id.editText);

var textView = FindViewById<TextView> (Resource.Id.textView);
  1. Implement the TextChanged event to capture the text from the EditText and write it to the TextView.
editText.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {

       textView.Text = e.Text.ToString ();

};

Additional Information

The EditText control also has events for handling other user interactions more such as when a key is pressed and before and after text is changed.