Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. package com.example.programmingknowledge.simpleloginapp;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.os.Bundle;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14.  
  15. public class Login extends ActionBarActivity {
  16. private static EditText username;
  17. private static EditText password;
  18. private static TextView attempts;
  19. private static Button login_btn;
  20. int attempt_counter = 5;
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_login);
  25. LoginButton();
  26. }
  27.  
  28. public void LoginButton() {
  29. username = (EditText)findViewById(R.id.editText_user);
  30. password = (EditText)findViewById(R.id.editText_password);
  31. attempts = (TextView)findViewById(R.id.textView_attemt_Count);
  32. login_btn = (Button)findViewById(R.id.button_login);
  33.  
  34. attempts.setText(Integer.toString(attempt_counter));
  35.  
  36. login_btn.setOnClickListener(
  37. new View.OnClickListener() {
  38. @Override
  39. public void onClick(View v) {
  40. if(username.getText().toString().equals("user") &&
  41. password.getText().toString().equals("pass") ) {
  42. Toast.makeText(Login.this,"User and Password is correct",
  43. Toast.LENGTH_SHORT).show();
  44. Intent intent = new Intent("com.example.programmingknowledge.simpleloginapp.User");
  45. startActivity(intent);
  46. } else {
  47. Toast.makeText(Login.this,"User and Password is not correct",
  48. Toast.LENGTH_SHORT).show();
  49. attempt_counter--;
  50. attempts.setText(Integer.toString(attempt_counter));
  51. if(attempt_counter == 0){
  52. login_btn.setEnabled(false);
  53. }
  54. }
  55.  
  56. }
  57. }
  58. );
  59. }
  60.  
  61. @Override
  62. public boolean onCreateOptionsMenu(Menu menu) {
  63. // Inflate the menu; this adds items to the action bar if it is present.
  64. getMenuInflater().inflate(R.menu.menu_login, menu);
  65. return true;
  66. }
  67.  
  68. @Override
  69. public boolean onOptionsItemSelected(MenuItem item) {
  70. // Handle action bar item clicks here. The action bar will
  71. // automatically handle clicks on the Home/Up button, so long
  72. // as you specify a parent activity in AndroidManifest.xml.
  73. int id = item.getItemId();
  74.  
  75. //noinspection SimplifiableIfStatement
  76. if (id == R.id.action_settings) {
  77. return true;
  78. }
  79.  
  80. return super.onOptionsItemSelected(item);
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement