LoginPage Validation With Alert Box for Android
Login.java
package sra.dem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Login extends Activity implements OnClickListener
{
Button login,clear;
AlertDialog dialog;
EditText unm,pwd;
@Override
public void onCreate(Bundle savedinstance)
{
super.onCreate(savedinstance);
setContentView(R.layout.main);
login=(Button)findViewById(R.id.login);
dialog=new AlertDialog.Builder(this).create();
dialog.setTitle(” MSG “);
this.login.setOnClickListener(this);
clear=(Button)findViewById(R.id.clear);
this.clear.setOnClickListener(this);
}
public void onClick(View v)
{
if(v==this.login)
{
unm=(EditText)findViewById(R.id.unm);
pwd=(EditText)findViewById(R.id.pwd);
String un=unm.getText().toString();
String pw=pwd.getText().toString();
if(un.equals(“”)||pw.equals(“”))
{
dialog.setMessage(” Enter Name & Password “);
dialog.setButton(” ok”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1)
{
return;
}
});
}
else
{
if(un.equals(“sravan”)||pw.equals(“sravan”))
{
//dialog.setMessage(” Yahoooo “);
Intent menuintent=new Intent(Demo.this,MenuControl.class);
startActivity(menuintent);
}
else
{
dialog.setMessage(” UserName or Password Error “);
}
dialog.setButton(” ok”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
return;
}
});
}
dialog.show();
}
else
{
unm.setText(“”);
pwd.setText(“”);
}
}
}
———————-
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Login extends Activity implements OnClickListener
{
Button login,clear;
AlertDialog dialog;
EditText unm,pwd;
@Override
public void onCreate(Bundle savedinstance)
{
super.onCreate(savedinstance);
setContentView(R.layout.main);
login=(Button)findViewById(R.id.login);
dialog=new AlertDialog.Builder(this).create();
dialog.setTitle(” MSG “);
this.login.setOnClickListener(this);
clear=(Button)findViewById(R.id.clear);
this.clear.setOnClickListener(this);
}
public void onClick(View v)
{
if(v==this.login)
{
unm=(EditText)findViewById(R.id.unm);
pwd=(EditText)findViewById(R.id.pwd);
String un=unm.getText().toString();
String pw=pwd.getText().toString();
if(un.equals(“”)||pw.equals(“”))
{
dialog.setMessage(” Enter Name & Password “);
dialog.setButton(” ok”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1)
{
return;
}
});
}
else
{
if(un.equals(“sravan”)||pw.equals(“sravan”))
{
//dialog.setMessage(” Yahoooo “);
Intent menuintent=new Intent(Demo.this,MenuControl.class);
startActivity(menuintent);
}
else
{
dialog.setMessage(” UserName or Password Error “);
}
dialog.setButton(” ok”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
return;
}
});
}
dialog.show();
}
else
{
unm.setText(“”);
pwd.setText(“”);
}
}
}
———————-
creating login screen using XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ffffff”
>
<ImageView
android:id=”@+id/main_logo”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:background=”@drawable/sisteer_logo_1″
android:layout_marginLeft=”-5dip”
android:layout_marginRight=”-5dip”
android:layout_marginTop=”-10dip”
/>
<TextView
android:id=”@+id/tunm”
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_marginLeft=”10dip”
android:layout_marginTop=”75dip”
android:text=”User Name :”
android:textColor=”#aa00aa”
/>
<EditText
android:id=”@+id/unm”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_marginRight=”5dip”
android:layout_marginTop=”65dip”
/>
<TextView
android:id=”@+id/tpwd”
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_marginLeft=”10dip”
android:layout_marginTop=”125dip”
android:text=” Password :”
android:textColor=”#aa00aa”
/>
<EditText
android:id=”@+id/pwd”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_marginRight=”5dip”
android:layout_marginTop=”120dip”
android:password=”true”
/>
<Button
android:id=”@+id/login”
android:text=” Login “
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_below=”@+id/pwd”
/>
<Button
android:id=”@+id/clear”
android:text=” Clear “
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginLeft=”180dip”
android:layout_marginTop=”168dip”
/>
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ffffff”
>
<ImageView
android:id=”@+id/main_logo”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:background=”@drawable/sisteer_logo_1″
android:layout_marginLeft=”-5dip”
android:layout_marginRight=”-5dip”
android:layout_marginTop=”-10dip”
/>
<TextView
android:id=”@+id/tunm”
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_marginLeft=”10dip”
android:layout_marginTop=”75dip”
android:text=”User Name :”
android:textColor=”#aa00aa”
/>
<EditText
android:id=”@+id/unm”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_marginRight=”5dip”
android:layout_marginTop=”65dip”
/>
<TextView
android:id=”@+id/tpwd”
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_marginLeft=”10dip”
android:layout_marginTop=”125dip”
android:text=” Password :”
android:textColor=”#aa00aa”
/>
<EditText
android:id=”@+id/pwd”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_marginRight=”5dip”
android:layout_marginTop=”120dip”
android:password=”true”
/>
<Button
android:id=”@+id/login”
android:text=” Login “
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginLeft=”100dip”
android:layout_below=”@+id/pwd”
/>
<Button
android:id=”@+id/clear”
android:text=” Clear “
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginLeft=”180dip”
android:layout_marginTop=”168dip”
/>
LoginPage Validation With Alert Box for Android
Reviewed by Anonymous
on
February 25, 2017
Rating:
No comments: