Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pe.edu.ulima.login;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity
- implements View.OnClickListener, View.OnLongClickListener{
- //TextView tviMensaje;
- EditText eteUsername, etePassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //tviMensaje = (TextView) findViewById(R.id.tviMensaje);
- eteUsername = (EditText) findViewById(R.id.eteUsername);
- etePassword = (EditText) findViewById(R.id.etePassword);
- Button butClick = (Button) findViewById(R.id.butClick);
- Button butSalir = (Button) findViewById(R.id.butSalir);
- //LoginClickListener loginClickListener = new LoginClickListener();
- //butClick.setOnClickListener(loginClickListener);
- butClick.setOnClickListener(this);
- //butSalir.setOnClickListener(this);
- butSalir.setOnLongClickListener(this);
- }
- @Override
- public void onClick(View view) {
- //Log.i("TAG","Se hizo click.");
- //tviMensaje.setText("Se hizo click.");
- if (view.getId() == R.id.butClick) {
- if (eteUsername.getText().toString().equals("android")
- && etePassword.getText().toString().equals("1234")) {
- //Login correcto
- Toast.makeText(this, "Login correcto", Toast.LENGTH_LONG).show();
- } else {
- //Login incorrecto
- eteUsername.setText("");
- etePassword.setText("");
- Toast.makeText(this, "Error en login", Toast.LENGTH_LONG).show();
- }
- }else if (view.getId() == R.id.butSalir){
- // Deberia salir de la app
- finish();
- }
- }
- @Override
- public boolean onLongClick(View view) {
- finish();
- return false;
- }
- }
- public class LoginClickListener implements View.OnClickListener {
- @Override
- public void onClick(View view) {
- Log.i("TAG","Se hizo click.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement