Exercise : 4
Create and Login
application as above . On successful login , open browser with any URL.
Screen Shot:
XML :
main.xml :
JAVA :
FourthActivity.java :
package kmn.Fourth;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class FourthActivity extends Activity implements OnClickListener,TextWatcher
{
/** @author Y@@D */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText username = (EditText)findViewById(R.id.txtusername);
EditText password = (EditText)findViewById(R.id.txtpassword);
username.addTextChangedListener(this);
password.addTextChangedListener(this);
Button login = (Button)findViewById(R.id.btnlogin);
login.setOnClickListener(this);
}
public void onClick(View v)
{
Intent i= new Intent("android.intent.action.VIEW");
i.setData(Uri.parse("http://www.kevalnagaria.blogspot.com"));
startActivity(i);
}
public void afterTextChanged(Editable s)
{
EditText e = (EditText)findViewById(R.id.txtusername);
EditText p = (EditText)findViewById(R.id.txtpassword);
Button b = (Button)findViewById(R.id.btnlogin);
if(e.getText().toString().equals("keval") && p.getText().toString().equals("nagaria"))
{
b.setEnabled(true);
}
else
{
b.setEnabled(false);
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}

