Advertisement
Guest User

Untitled

a guest
May 12th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. package com.example.soft_1.loginthing;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.TextView;
  9.  
  10. public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  11. static String premadeUsername = "Gigi";
  12. static String premadePassword = "1234567";
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17. Button btnLogin = (Button) findViewById(R.id.btn_Login);
  18. btnLogin.setOnClickListener(this);
  19.  
  20. Button btnCancel = (Button) findViewById(R.id.btn_Cancel);
  21. btnCancel.setOnClickListener(this);
  22. }
  23. public void onClick(View v) {
  24. Button btnLogin = (Button) findViewById(R.id.btn_Login);
  25. Button btnCancel = (Button) findViewById(R.id.btn_Cancel);
  26. EditText etPassword = (EditText)findViewById(R.id.etxt_Password);
  27. EditText etUsername = (EditText)findViewById(R.id.etxt_Username);
  28. TextView txtError = (TextView)findViewById(R.id.txt_error);
  29.  
  30. switch (v.getId()) {
  31. case R.id.btn_Login:
  32. if(etPassword.getText().toString().length() < 6)
  33. {
  34. txtError.setVisibility(View.VISIBLE);
  35. txtError.setText("Password cannot be shorter than 6 letters");
  36. }
  37. else
  38. if(etPassword.getText().toString() == premadePassword && etUsername.getText().toString() == premadeUsername )
  39. {
  40. txtError.setVisibility(View.VISIBLE);
  41. txtError.setText("Logged in!");
  42. }
  43. else
  44. {
  45. txtError.setVisibility(View.VISIBLE);
  46. txtError.setText("Username or Password is incorrect lol");
  47. }
  48.  
  49. break;
  50. case R.id.btn_Cancel:
  51. finish();
  52. break;
  53. }
  54. }
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. <?xml version="1.0" encoding="utf-8"?>
  66. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  67. xmlns:app="http://schemas.android.com/apk/res-auto"
  68. xmlns:tools="http://schemas.android.com/tools"
  69. android:layout_width="match_parent"
  70. android:layout_height="match_parent"
  71. tools:context=".MainActivity">
  72.  
  73. <TextView
  74. android:textSize="50dp"
  75. android:id="@+id/txt_Login"
  76. android:layout_marginTop="20dp"
  77. android:layout_centerHorizontal="true"
  78. android:layout_width="wrap_content"
  79. android:layout_height="wrap_content"
  80. android:text="Login"
  81. tools:layout_editor_absoluteX="163dp"
  82. tools:layout_editor_absoluteY="52dp" />
  83.  
  84. <TextView
  85. android:textSize="18dp"
  86. android:id="@+id/txt_Username"
  87. android:layout_width="wrap_content"
  88. android:layout_height="wrap_content"
  89. android:layout_alignBaseline="@+id/etxt_Username"
  90. android:layout_alignParentStart="true"
  91. android:layout_marginStart="18dp"
  92. android:text="Username:"
  93. tools:layout_editor_absoluteX="59dp"
  94. tools:layout_editor_absoluteY="169dp" />
  95.  
  96. <TextView
  97. android:textSize="18dp"
  98. android:id="@+id/txt_Password"
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:layout_alignBaseline="@+id/etxt_Password"
  102. android:layout_alignStart="@+id/txt_Username"
  103. android:text="Password:"
  104. tools:layout_editor_absoluteX="59dp"
  105. tools:layout_editor_absoluteY="222dp" />
  106.  
  107. <EditText
  108. android:id="@+id/etxt_Username"
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:layout_alignParentEnd="true"
  112. android:layout_alignParentTop="true"
  113. android:layout_marginEnd="48dp"
  114. android:layout_marginTop="115dp"
  115. android:ems="10"
  116. android:inputType="textPersonName"
  117. android:hint="Username"
  118. tools:layout_editor_absoluteX="129dp"
  119. tools:layout_editor_absoluteY="157dp" />
  120.  
  121. <Button
  122. android:id="@+id/btn_Login"
  123. android:layout_width="wrap_content"
  124. android:layout_height="wrap_content"
  125. android:layout_alignParentStart="true"
  126. android:layout_alignTop="@+id/btn_Cancel"
  127. android:layout_marginStart="31dp"
  128. android:text="Login"
  129. android:textSize="30dp"
  130. tools:layout_editor_absoluteX="73dp"
  131. tools:layout_editor_absoluteY="332dp" />
  132.  
  133. <Button
  134. android:id="@+id/btn_Cancel"
  135. android:layout_width="wrap_content"
  136. android:layout_height="wrap_content"
  137. android:layout_alignParentBottom="true"
  138. android:layout_alignParentEnd="true"
  139. android:layout_marginBottom="83dp"
  140. android:layout_marginEnd="31dp"
  141. android:text="Cancel"
  142. android:textSize="30dp"
  143. tools:layout_editor_absoluteX="207dp"
  144. tools:layout_editor_absoluteY="332dp" />
  145.  
  146. <EditText
  147. android:id="@+id/etxt_Password"
  148. android:layout_width="wrap_content"
  149. android:layout_height="wrap_content"
  150. android:layout_alignParentTop="true"
  151. android:layout_alignStart="@+id/etxt_Username"
  152. android:layout_marginTop="211dp"
  153. android:ems="10"
  154. android:hint="Password"
  155. android:inputType="textPassword"
  156. tools:layout_editor_absoluteX="126dp"
  157. tools:layout_editor_absoluteY="214dp" />
  158.  
  159. <TextView
  160. android:textSize="30dp"
  161. android:id="@+id/txt_error"
  162. android:layout_width="wrap_content"
  163. android:layout_height="wrap_content"
  164. android:layout_alignParentBottom="true"
  165. android:layout_centerHorizontal="true"
  166. android:layout_marginBottom="187dp"
  167. android:text="Error"
  168. android:visibility="invisible"/>
  169. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement