Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.example.restoalan;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. public class RegistrasiActivity extends AppCompatActivity {
  13.     DatabaseHelper db;
  14.     Button login, register;
  15.     EditText username, password, passwordConf;
  16.  
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_registrasi);
  22.  
  23.  
  24.         db = new DatabaseHelper(this);
  25.  
  26.         username = (EditText)findViewById(R.id.edtText_usernameRegist);
  27.         password = (EditText)findViewById(R.id.edtText_passwordRegist);
  28.         passwordConf = (EditText)findViewById(R.id.edtText_passwordConfRegist);
  29.         login = (Button)findViewById(R.id.btn_loginRegist);
  30.         register = (Button)findViewById(R.id.btn_registerRegist);
  31.  
  32.         //login
  33.         login.setOnClickListener(new View.OnClickListener() {
  34.             @Override
  35.             public void onClick(View v) {
  36.                 Intent loginIntent = new Intent(RegistrasiActivity.this, LoginActivity.class);
  37.                 startActivity(loginIntent);
  38.                 finish();
  39.             }
  40.         });
  41.  
  42.         //register
  43.         register.setOnClickListener(new View.OnClickListener() {
  44.             @Override
  45.             public void onClick(View v) {
  46.                 String strUsername = username.getText().toString();
  47.                 String strPassword = password.getText().toString();
  48.                 String strPasswordConf = passwordConf.getText().toString();
  49.                 if (strPassword.equals(strPasswordConf)) {
  50.                     Boolean daftar = db.insertUser(strUsername, strPassword);
  51.                     if (daftar == true) {
  52.                         Toast.makeText(getApplicationContext(), "Daftar Berhasil", Toast.LENGTH_SHORT).show();
  53.                         Intent loginIntent = new Intent(RegistrasiActivity.this, LoginActivity.class);
  54.                         startActivity(loginIntent);
  55.                         finish();
  56.                     }
  57.                     else {
  58.                         Toast.makeText(getApplicationContext(), "Daftar Gagal", Toast.LENGTH_SHORT).show();
  59.                     }
  60.                 }
  61.                 else {
  62.                     Toast.makeText(getApplicationContext(), "Password Tidak Cocok", Toast.LENGTH_SHORT).show();
  63.                 }
  64.             }
  65.         });
  66.     }
  67. }