How to implement OTP Layout and Coding in Android
How to implement OTP (One Time Password) Layout and Coding in Android.
100% Working Code and Projects.
if you need any help about project and Application Contact Shelly at:+917889163814.
See Code Below and Download Project Free.
Java File
MainActivity.java
package com.example.otpproject;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText e1, e2, e3, e4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.editText1);
e2 = (EditText) findViewById(R.id.editText2);
e3 = (EditText) findViewById(R.id.editText3);
e4 = (EditText) findViewById(R.id.editText4);
e1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (e1.getText().toString().length() == 1) {
e2.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
e2.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (e2.getText().toString().length() == 1) {
e3.requestFocus();
}
else
{
e1.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
e3.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (e3.getText().toString().length() == 1) {
e4.requestFocus();
}
else
{
e2.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
e4.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (e4.getText().toString().length() == 1) {
}
else
{
e3.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
}
}
Xml Code
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#dddd00"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Working OTP Layout"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/editText1"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#ffff00"
android:gravity="center"
android:hint="-"
android:inputType="number"
android:textColorHint="#000000"
android:textSize="20dp"
android:textStyle="bold" >
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:background="#ffff00"
android:gravity="center"
android:hint="-"
android:inputType="number"
android:textColorHint="#000000"
android:textSize="20dp"
android:textStyle="bold" >
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:background="#ffff00"
android:gravity="center"
android:hint="-"
android:inputType="number"
android:textColorHint="#000000"
android:textSize="20dp"
android:textStyle="bold" >
</EditText>
<EditText
android:id="@+id/editText4"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:background="#ffff00"
android:gravity="center"
android:hint="-"
android:inputType="number"
android:textColorHint="#000000"
android:textSize="20dp"
android:textStyle="bold" >
</EditText>
</LinearLayout>
</LinearLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.otpproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Screenshot Given Below:
for Download click here:-https://drive.google.com/open?id=1dUGwQCI771OF4C2feB1iUR-QmuFwqx8P
Comments
Post a Comment