Guest User

Untitled

a guest
Oct 25th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. EditText username;
  4. EditText password;
  5. Button loginbutton;
  6. DataModel data;
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_main);
  12.  
  13. data = new DataModel();
  14.  
  15. data.setUsername("Don");
  16. data.setPassword("Bradman");
  17.  
  18. username = (EditText) findViewById(R.id.editusername);
  19. password = (EditText) findViewById(R.id.editpassword);
  20.  
  21. loginbutton = (Button) findViewById(R.id.loginbutton);
  22. loginbutton.setOnClickListener(new View.OnClickListener() {
  23. public void onClick(View v) {
  24. // Perform action on click
  25. if (username.getText().toString().equals("Prashant") && password.getText().toString().equals("Joshi")){
  26. Toast.makeText(MainActivity.this, "You have successfully logged in", Toast.LENGTH_SHORT).show();
  27. }
  28. else {
  29. Toast.makeText(MainActivity.this, "Wrong Username or Password", Toast.LENGTH_SHORT).show();
  30. }
  31. }
  32. });
  33.  
  34. }
  35. }
  36.  
  37. public class DataModel {
  38.  
  39. String username;
  40. String password;
  41.  
  42. public String getUsername() {
  43. return username;
  44. }
  45.  
  46. public void setUsername(String username) {
  47. this.username = username;
  48. }
  49.  
  50. public String getPassword() {
  51. return password;
  52. }
  53.  
  54. public void setPassword(String password) {
  55. this.password = password;
  56. }
  57. }
  58.  
  59. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  60. xmlns:tools="http://schemas.android.com/tools"
  61. android:layout_width="match_parent"
  62. android:layout_height="match_parent"
  63. android:orientation="vertical"
  64. android:paddingBottom="10dp"
  65. android:paddingLeft="10dp"
  66. android:paddingRight="10dp"
  67. android:paddingTop="10dp"
  68. >
  69.  
  70. <EditText
  71. android:id="@+id/editusername"
  72. android:layout_width="match_parent"
  73. android:layout_height="wrap_content"
  74. android:hint="Username"
  75. android:inputType="textNoSuggestions"/>
  76.  
  77. <EditText
  78. android:id="@+id/editpassword"
  79. android:layout_width="match_parent"
  80. android:layout_height="wrap_content"
  81. android:hint="Password"
  82. android:inputType="textPassword"/>
  83.  
  84. <Button
  85. android:id="@+id/loginbutton"
  86. android:layout_width="match_parent"
  87. android:layout_height="wrap_content"
  88. android:onClick="onLoginClicked"
  89. android:text="Login Button"/>
  90. </LinearLayout>
Add Comment
Please, Sign In to add comment