Question -3
Step 1: Create New Project in Eclipse.
Step 2: Edit Main Layout XML file from res/layout folder
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30dp"
android:text="@string/username" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="@string/password" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password" />
</TableRow>
<TableRow>
<Button android:text="@string/login" android:id="@+id/btnlogin" android:enabled="false"/>
</TableRow>
</TableLayout>
Step 3: Edit MainActivity.java file from scr/package/ folder
package com.example.login;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
public class MainActivity extends Activity implements OnClickListener,TextWatcher
{
Button login;
EditText uname;
EditText pwd;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uname = (EditText)findViewById(R.id.uid);
pwd = (EditText)findViewById(R.id.pwd);
login = (Button)findViewById(R.id.btnlogin);
login.setOnClickListener(this);
uname.addTextChangedListener(this);
pwd.addTextChangedListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v)
{
Toast.makeText(this,"Sucess",Toast.LENGTH_LONG).show();
}
@Override
public void afterTextChanged(Editable e)
{
if(uname.getText().toString().equalsIgnoreCase("sahin") && pwd.getText().toString().equalsIgnoreCase("raj"))
{
login.setEnabled(true);
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
}
}
Step 2: Edit Main Layout XML file from res/layout folder
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30dp"
android:text="@string/username" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="@string/password" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password" />
</TableRow>
<TableRow>
<Button android:text="@string/login" android:id="@+id/btnlogin" android:enabled="false"/>
</TableRow>
</TableLayout>
Step 3: Edit MainActivity.java file from scr/package/ folder
package com.example.login;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
public class MainActivity extends Activity implements OnClickListener,TextWatcher
{
Button login;
EditText uname;
EditText pwd;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uname = (EditText)findViewById(R.id.uid);
pwd = (EditText)findViewById(R.id.pwd);
login = (Button)findViewById(R.id.btnlogin);
login.setOnClickListener(this);
uname.addTextChangedListener(this);
pwd.addTextChangedListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v)
{
Toast.makeText(this,"Sucess",Toast.LENGTH_LONG).show();
}
@Override
public void afterTextChanged(Editable e)
{
if(uname.getText().toString().equalsIgnoreCase("sahin") && pwd.getText().toString().equalsIgnoreCase("raj"))
{
login.setEnabled(true);
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
}
}
No comments:
Post a Comment