Android Javascript Ajax Html PHP Example

Android EditText or Input Box with Examples


In this example we will discuss how to create a EditText or Input Box with Examples.

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="40dp"
    android:orientation="vertical" android:id="@+id/linearlayout" >
    <EditText
        android:id="@+id/txtName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:layout_marginRight="50dp"
        android:ems="10"
        android:hint="Name"
        android:inputType="text"
        android:selectAllOnFocus="true" />

    <EditText
        android:id="@+id/txtEmai"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="50dp"
        android:ems="10"
        android:hint="Email"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/txtPhone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_marginRight="50dp"
        android:hint="Phone Number"
        android:inputType="phone"
        android:textColorHint="#FE8DAB"/>
    <EditText
        android:id="@+id/txtPwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="50dp"
        android:hint="Password"
        android:inputType="textPassword" />
    <Button
        android:id="@+id/btnSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="submit"
        android:textSize="12sp"
        android:minHeight="30dp"
        android:background="#8000ff"
        android:textColor="#FFFFFF"
        android:textStyle="normal|bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/resultView"
        android:layout_marginTop="25dp"
        android:textSize="15dp"/>
</LinearLayout>


MainActivity.java


package com.example.edittext;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    Button btnSubmit;
    EditText name, password, email,  phoneno;
    TextView result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name=(EditText)findViewById(R.id.txtName);
        password = (EditText)findViewById(R.id.txtPwd);
        email = (EditText)findViewById(R.id.txtEmai);
        phoneno= (EditText)findViewById(R.id.txtPhone);
        btnSubmit = (Button)findViewById(R.id.btnSend);
        result = (TextView)findViewById(R.id.resultView);
    }
}