Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Latest commit

 

History

History

capture_user_input_text

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
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.