Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.practice.mobile.labquiz;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- private EditText username, password, city;
- private SharedPreferences shared;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username = findViewById(R.id.editText3);
- password = findViewById(R.id.editText2);
- city = findViewById(R.id.editText5);
- shared = getSharedPreferences("com.practice.mobile.labquiz", MODE_PRIVATE);
- }
- public void signUp(View view) {
- String uString = username.getText().toString();
- String pString = password.getText().toString();
- String cString = city.getText().toString();
- if (uString.equals("") || pString.equals("") || cString.equals("")) {
- Toast.makeText(this, "The fields cannot be empty!", Toast.LENGTH_LONG).show();
- } else if (pString.length() < 4) {
- Toast.makeText(this, "The password cannot be shorter than 4 characters!", Toast.LENGTH_LONG).show();
- } else if (uString.length() > 5) {
- Toast.makeText(this, "The username cannot be longer than 5 characters!", Toast.LENGTH_LONG).show();
- } else {
- shared.edit().putString("username", uString).apply();
- shared.edit().putString("password", pString).apply();
- shared.edit().putString("city", cString).apply();
- Toast.makeText(this, "Successfully created an account", Toast.LENGTH_LONG).show();
- Intent intent = new Intent(MainActivity.this, LoginActivity.class);
- startActivity(intent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement