Advertisement
bernardje

Untitled

Apr 7th, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package bernard.bernardjulyansyah_161011400019;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. public class login extends AppCompatActivity {
  13.  
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. final EditText username, password;
  17. Button btnLogin;
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_login);
  20.  
  21. username = (EditText) findViewById(R.id.txt1);
  22. password = (EditText) findViewById(R.id.txt2);
  23. btnLogin = (Button) findViewById(R.id.btn1);
  24.  
  25. btnLogin.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28.  
  29. String usernameKey = username.getText().toString();
  30. String passwordKey = password.getText().toString();
  31.  
  32. if (usernameKey.equals("bernard") && passwordKey.equals("123")) {
  33. //jika login berhasil
  34. Toast.makeText(getApplicationContext(), "LOGIN SUKSES",
  35. Toast.LENGTH_SHORT).show();
  36. Intent intent = new Intent(login.this, menupilihan.class);
  37. login.this.startActivity(intent);
  38. finish();
  39. } else {
  40. //jika login gagal
  41. AlertDialog.Builder builder = new AlertDialog.Builder(login.this);
  42. builder.setMessage("Username atau Password Anda salah!")
  43. .setNegativeButton("Retry", null).create().show();
  44. }
  45. }
  46.  
  47. });
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement