Advertisement
Guest User

Class Excersice 0 2016 08 22

a guest
Aug 22nd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. MAinActivity
  2.  
  3. package com.example.z.myapplication;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7.  
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.EditText;
  11.  
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15.  
  16. public class MainActivity extends Activity {
  17.  
  18. EditText txtUserName;
  19. EditText txtUserPass;
  20. TextView lblMsg;
  21. final String MY_USER="zeev";
  22. final String MY_PASS="12345";
  23. final String USER="Zeev Mindely";
  24. private int totalTry=5;
  25.  
  26.  
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_main);
  31. setPointer();
  32. }
  33.  
  34. private void setPointer()
  35. {
  36. txtUserName=(EditText)findViewById(R.id.txtUserName);
  37. txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
  38. lblMsg=(TextView)findViewById(R.id.lblMsg);
  39.  
  40.  
  41. }
  42.  
  43.  
  44. public void btnClick(View view)
  45. {
  46. String getUser=txtUserName.getText().toString();
  47. String getPass=txtUserPass.getText().toString();
  48.  
  49. if (totalTry==0) {
  50. Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
  51. return;
  52. }
  53.  
  54. if (getUser.equals(MY_USER) && getPass.equals(MY_PASS))
  55. {
  56. //lblMsg.setText("User loged...");
  57. Intent myInt = new Intent(this,Main2Activity.class);
  58. myInt.putExtra("Main2Activity",this.USER);
  59. startActivity(myInt);
  60. finish();
  61. }
  62. else
  63. {
  64. totalTry--;
  65. Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
  66.  
  67. }
  68. }
  69.  
  70. }
  71.  
  72. activity Main
  73.  
  74. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  75. android:layout_width="match_parent"
  76. android:layout_height="match_parent"
  77. android:orientation="vertical">
  78.  
  79. <LinearLayout
  80. android:layout_width="match_parent"
  81. android:layout_height="150dp"
  82. android:orientation="vertical">
  83.  
  84. <TextView
  85. android:layout_width="match_parent"
  86. android:layout_height="match_parent"
  87. android:gravity="center"
  88. android:text="LOGO"
  89. android:textSize="100sp">
  90.  
  91. </TextView>
  92. </LinearLayout>
  93.  
  94. <LinearLayout
  95. android:layout_width="match_parent"
  96. android:layout_height="150dp"
  97. android:orientation="vertical">
  98.  
  99. <EditText
  100. android:id="@+id/txtUserName"
  101. android:layout_width="match_parent"
  102. android:layout_height="wrap_content"
  103. android:hint="Enter your name...."
  104. android:inputType="text"
  105. android:textSize="22sp" />
  106.  
  107. <EditText
  108. android:id="@+id/txtUserPassword"
  109. android:layout_width="match_parent"
  110. android:layout_height="wrap_content"
  111. android:hint="Enter Password..."
  112. android:inputType="textPassword"
  113. android:textSize="22sp" />
  114. </LinearLayout>
  115.  
  116. <LinearLayout
  117. android:layout_width="match_parent"
  118. android:layout_height="70dp"
  119. android:orientation="vertical">
  120.  
  121. <Button
  122. android:layout_width="match_parent"
  123. android:layout_height="wrap_content"
  124. android:text="Login"
  125. android:background="#91E0FF"
  126. android:textColor="#ffffff"
  127. android:textSize="32sp"
  128. android:onClick="btnClick"/>
  129. </LinearLayout>
  130.  
  131. <LinearLayout
  132. android:layout_width="match_parent"
  133. android:layout_height="match_parent"
  134. android:orientation="vertical">
  135. <TextView
  136. android:layout_width="match_parent"
  137. android:layout_height="match_parent"
  138. android:textSize="32sp"
  139. android:text="MY LOGIN SYSTEM V1"
  140. android:gravity="center"
  141. android:id="@+id/lblMsg"/>
  142. </LinearLayout>
  143. </LinearLayout>
  144.  
  145.  
  146. MAin2Activity
  147.  
  148. package com.example.z.myapplication;
  149.  
  150. import android.content.Intent;
  151. import android.support.v7.app.AppCompatActivity;
  152. import android.os.Bundle;
  153. import android.widget.TextView;
  154.  
  155. public class Main2Activity extends MainActivity {
  156.  
  157. TextView myText;
  158.  
  159.  
  160. @Override
  161. protected void onCreate(Bundle savedInstanceState) {
  162. super.onCreate(savedInstanceState);
  163. setContentView(R.layout.activity_main2);
  164. setPointer();
  165. myText.setText(getIntent().getStringExtra("Main2Activity"));
  166.  
  167.  
  168. }
  169.  
  170. public void setPointer(){
  171.  
  172. myText=(TextView)findViewById(R.id.USER);
  173.  
  174.  
  175. }
  176. }
  177.  
  178.  
  179. activity main 2
  180.  
  181. <?xml version="1.0" encoding="utf-8"?>
  182. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  183. xmlns:tools="http://schemas.android.com/tools"
  184. android:layout_width="match_parent"
  185. android:layout_height="match_parent"
  186. android:paddingBottom="@dimen/activity_vertical_margin"
  187. android:paddingLeft="@dimen/activity_horizontal_margin"
  188. android:paddingRight="@dimen/activity_horizontal_margin"
  189. android:paddingTop="@dimen/activity_vertical_margin"
  190. tools:context="com.example.z.myapplication.Main2Activity">
  191.  
  192.  
  193. <LinearLayout
  194. android:layout_width="match_parent"
  195. android:layout_height="match_parent"
  196. >
  197. <TextView
  198. android:layout_width="match_parent"
  199. android:layout_height="match_parent"
  200. android:gravity="center"
  201.  
  202. android:layout_margin="12dp"
  203. android:textSize="36dp"
  204. android:id="@+id/USER"/>
  205.  
  206.  
  207. </LinearLayout>
  208.  
  209. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement