Download Code

Android Studio EditText Example

In android studio edittext example you will learn how to use Edit Text in 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.

Edit Text

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.

Create android studio edittext example application project.Then go to your activity_main.xml file and add EditText,Button.

android studio edittext,android studio edittext example,edittext example,edittext,

After that go to your class and do the following steps.

  • Create/declare variables for EditText,Button.
  • Create a public method to refer id’s of UI Components.
  • Apply click event on button
  • Display toast of edittext on button click.

package com.example.anonymous.studioedittext;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    EditText userInput;   // user input variable
    Button displayInput;  // button variable
    protected void onCreate(Bundle savedInstanceState) {
        initialize();  // calling user defined method
        // apply click event on button
        displayInput.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                // displaying toast and also getting user input using getText() method
                Toast.makeText(getApplicationContext(), userInput.getText(), Toast.LENGTH_SHORT).show();
    // user defined method
    private void initialize(){
        userInput = (EditText) findViewById(;   // refering id of edit text
        displayInput = (Button) findViewById(;    // refering id of button


Compile and run your android studio edittext example application project.

android studio edittext,android studio edittext example,edittext example,edittext,

That’s it for this android studio edittext example.

Don’t forget to leave your feedback.