Advertisement
Guest User

Untitled

a guest
May 31st, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package com.practice.mobile.labquiz;
  2.  
  3. import android.content.Intent;
  4. import android.content.SharedPreferences;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.EditText;
  9. import android.widget.Toast;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12. private EditText username, password, city;
  13. private SharedPreferences shared;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19.  
  20. username = findViewById(R.id.editText3);
  21. password = findViewById(R.id.editText2);
  22. city = findViewById(R.id.editText5);
  23. shared = getSharedPreferences("com.practice.mobile.labquiz", MODE_PRIVATE);
  24. }
  25.  
  26. public void signUp(View view) {
  27. String uString = username.getText().toString();
  28. String pString = password.getText().toString();
  29. String cString = city.getText().toString();
  30.  
  31. if (uString.equals("") || pString.equals("") || cString.equals("")) {
  32. Toast.makeText(this, "The fields cannot be empty!", Toast.LENGTH_LONG).show();
  33. } else if (pString.length() < 4) {
  34. Toast.makeText(this, "The password cannot be shorter than 4 characters!", Toast.LENGTH_LONG).show();
  35. } else if (uString.length() > 5) {
  36. Toast.makeText(this, "The username cannot be longer than 5 characters!", Toast.LENGTH_LONG).show();
  37. } else {
  38. shared.edit().putString("username", uString).apply();
  39. shared.edit().putString("password", pString).apply();
  40. shared.edit().putString("city", cString).apply();
  41. Toast.makeText(this, "Successfully created an account", Toast.LENGTH_LONG).show();
  42.  
  43. Intent intent = new Intent(MainActivity.this, LoginActivity.class);
  44. startActivity(intent);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement