addTextChangedListener in Android example
Create login application where you will have to validate EmailID(UserName). Till the user name and password is not validated , login button should remain disabled.
File Name : E3Activity.java
package bsr.exa;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class E3Activity extends Activity {
/** @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.in
*
* 3) Create login application where you will have to validate EmailID(UserName).
* Till the user name and password is not validated , login button should remain disabled.
**/
String uname="rupadiyabipin@gmail.com";
String pwd="bipin";
boolean usrStatus=false;
boolean pwdStatus=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//create an intent
final Intent intent=new Intent(this,Screen2.class);
final Button cmdLogin = (Button) findViewById(R.id.cmdLogin);
final EditText txtUsr = (EditText)findViewById(R.id.txtUsr);
final EditText txtPwd = (EditText)findViewById(R.id.txtPwd);
cmdLogin.setEnabled(false);
cmdLogin.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
intent.putExtra("uname1", txtUsr.getText().toString());
intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//Toast.makeText(E3Activity.this, "welcome ".txtUser.getText().toString().concat(" you are authenticated user! "), Toast.LENGTH_LONG).show();
}
});
//------------------------------------------------
//clear event
final Button btnClear = (Button)findViewById(R.id.cmdClear);
btnClear.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
EditText fldu=(EditText)findViewById(R.id.txtUsr);
EditText fldp=(EditText)findViewById(R.id.txtPwd);
fldu.setText("");
fldp.setText("");
}
});
//------------------------------------------------
txtUsr.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
if(uname.equals(txtUsr.getText().toString()))
{
usrStatus=true;
}
else
{
usrStatus=false;
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
if(usrStatus && pwdStatus)
{
cmdLogin.setEnabled(true);
}
else
{
cmdLogin.setEnabled(false);
}
}
});
txtPwd.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
if(pwd.equals(txtPwd.getText().toString()))
{
pwdStatus=true;
}
else
{
pwdStatus=false;
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
if(usrStatus && pwdStatus)
{
cmdLogin.setEnabled(true);
}
else
{
cmdLogin.setEnabled(false);
}
}
});
}
}
File Name : Screen2.java
package bsr.exa;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
/** @author Bipin S Rupadiya , www.gtu-android.blogspot.com
*
*
*
**/
public class Screen2 extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent=getIntent();
String uname=intent.getStringExtra("uname1");
TextView tv=new TextView(this);
Button btnBack = new Button(this);
btnBack.setText("<<Back");
tv.setText("Welcome "+uname+" !");
tv.setTextColor(Color.rgb(255, 255, 255));
tv.setTextSize(25);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv);
ll.addView(btnBack);
setContentView(ll);
//------------------------------------------------
//back event
btnBack.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
setContentView(R.layout.main);
}
});
//------------------------------------------------
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bsr.exa"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".E3Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Screen2"></activity>
</application>
</manifest>
Labels:
Android,
Mobile Computing
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Blog Archive
-
▼
2012
(79)
-
▼
September
(22)
- Chapter 7, Memory Management
- Chapter 6, Concurrency: Deadlock and Starvation
- Chapter 5, Concurrency: Mutual Exclusion and Sync...
- Chapter 4, Threads, SMP, and Micro kernels
- Chapter 3, Process Description and Control
- Chapter 2, Operating System Overview
- Chapter 1, Computer System Overview
- menu in android tutorial
- android animation example
- android chronometer example
- spinner in android example
- listview in android
- implicit intent in android example
- addTextChangedListener in Android example
- Be a Freelances and earn $$$$
- View SQLite Database
- Write a shell script to delete zero sized files fr...
- Android Intent Example
- Hello World in Android
- SQLite Android Tutorial
- Happy Teachers' Day
- Thank you GOD
-
▼
September
(22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
Good work
Post a Comment